-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Bug Report
I have read:
I am using the latest version of the library.
v 0.26.0
Expected Behavior
I was trying to run the bot after writing some lines of code. I expected that after runningnode index.js
,
there will be no errors and when i send a request from telegram, get the desired result.
Actual Behavior
what happened instead was this error in the console
class TelegramBot extends EventEmitter {
^^^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (E:\Code\dobo\node_modules\node-telegram-bot-api\index.js:12:20)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
So i run this instead node --use_strict index.js
and got different set of errors
constructor(token, options = {}) {
^
SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (E:\Code\dobo\node_modules\node-telegram-bot-api\index.js:12:20)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
So after a while, I went through telegram.js
and telegramPolling.js
and changed the following function parameters
- options = {} to options
- forms = {} to forms
- fileOpts = {} to fileOpts
and in some cases, initialized the variable to an empty object within the function. For example
startPolling(options) {
options = {};
if (this.hasOpenWebHook()) {
return Promise.reject(new Error('Polling and WebHook are mutually exclusive'));
}
options.restart = typeof options.restart === 'undefined' ? true : options.restart;
if (!this._polling) {
this._polling = new TelegramBotPolling(this._request.bind(this), this.options.polling, this.processUpdate.bind(this));
}
return this._polling.start(options);
}
It was after taking these steps that it finally worked
Steps to reproduce the Behavior
- write an index.js file with following code
var token = '<insert token here>';
var Bot = require('node-telegram-bot-api'),
bot = new Bot(token, { polling: true });
bot.onText(/^\/say_hello (.+)$/, function (msg, match) {
var name = match[1];
bot.sendMessage(msg.chat.id, 'Hello ' + name + '!').then(function () {
// reply sent!
});
});
- run
node index.js
Question
My project, as at now, only tests sending messages but I could test other features If given approval