Closed jgsmarques closed 5 years ago
Hi! That was pretty complex to debug.
Seems like telegraf does not process text message /start
as a command. I suppose there should be another markup to pass command to bot from client correctly. Right now I can't look it up, but PR would be great.
For now, you can replace botInstance.command('start')
with botInstance.hears('/start')
as I added a test example here - and it will work.
Hi,
This is the implementation for the command
method in Telegraf:
static command (command, ...fns) {
if (fns.length === 0) {
return Composer.entity(['bot_command'], command)
}
const commands = normalizeTextArguments(command, '/')
return Composer.mount('text', Composer.lazy((ctx) => {
const groupCommands = ctx.me && (ctx.chat.type === 'group' || ctx.chat.type === 'supergroup')
? commands.map((command) => `${command}@${ctx.me}`)
: []
return Composer.entity(({ offset, type }, value) =>
offset === 0 &&
type === 'bot_command' &&
(commands.includes(value) || groupCommands.includes(value))
, ...fns)
}))
}
From a naive approach, I would say that the type === 'bot_command'
might be the issue. I will need to investigate further to check if this is something that Telegraf computes before at some other level (when parsing a message from Telegram) or something it expects Telegram to send already filled out.
Whenever I get a chance I'll try to examine a little deeper.
Thanks anyway for the quick response!
I've done a quick find in the Telegraf source code and the only place I can find the 'bot_command' string is exactly in the method I posted. Therefore, it seems that Telegraf expects Telegram to send that value in messages.
Does this framework do anything related to this when processing commands? If not, that might be the issue.
@tigermarques Great! It helped to implement client methods "makeCommand" and "sendCommand". With this, your code works with bot.command('start')
!
Please check version 2.2.1 on npm.
Works like a charm! Thanks a lot!
Thank you for your comments! This API is pretty simple and raw since I am the only developer and I only use it time to time for my own projects, so you can find other missing features. But surely we can implement them :)
Hi,
I'm trying to use your framework to test a bot that I'm building using Telegraf.
I'm facing issues in getting messages created with this API to reach my bot. My bot has the following implementation:
When I run my test, it fails and I do not understand why.
However, if I replace the start command of the bot with
botInstance.on('message', ctx => ctx.reply('Hi'))
, my bot will actually answer and the test will pass. So the messages are definitely arriving Telegraf (I've set some debug points on their code and I can see that all messages sent via your framework reach the bot), but somehow their format is preventing them from reaching my code when using Telegraf commands.Can you help me identify what the problem is, or if I should be sending the messages in a different format for them to reach Telegraf correctly?
Thank you very much!