telegram-bot-ruby icon indicating copy to clipboard operation
telegram-bot-ruby copied to clipboard

How to listen /command@bot in supergroup?

Open ghost opened this issue 8 years ago • 10 comments

In supergroup, I can use /command trigger the bot, but /command@bot cannot trigger the bot.

ghost avatar Oct 02 '17 23:10 ghost

@iVanilla does your bot receive /command@bot message at all? Could you check in you logs?

ivanovaleksey avatar Oct 03 '17 05:10 ivanovaleksey

@ivanovaleksey No, only received /command.

Where is the logs file path?

ghost avatar Oct 05 '17 15:10 ghost

Hi @ivanovaleksey, messages are coming. But now bot doesn't triggered by them :( Is there only one way to fix it? (by adding /command@bot_name to our cases)

GanjMonk avatar Oct 28 '17 19:10 GanjMonk

@iVanilla i think you should set the bot as the admin of the group ... it should works

eVanilla avatar Oct 28 '17 19:10 eVanilla

@eVanilla didn't help :( Incoming messages still coming like /command@bot_name may be we talking about different problems :)

GanjMonk avatar Oct 28 '17 20:10 GanjMonk

I don't have very much experience about using bots in groups. But the situation seems pretty clear. Let's look at the official documentation on commands:

If multiple bots are in a group, it is possible to add bot usernames to commands in order to avoid confusion: /start@TriviaBot /start@ApocalypseBot This is done automatically when commands are selected via the list of suggestions. Please remember that your bot needs to be able to process commands that are followed by its username.

So, it is totally up to developer how to trigger on a message. If your bot is in a group and you just check command name (and don't check which bot the command is addressed to) it might be ambiguous situation.

As about ways of "fixing" it. Yes, the most obvious would be to add switches with explicit bot name. I guess In Ruby you can even create a nice little wrapper for it.

Also please note that you can check chat's type. For instance

#<Telegram::Bot::Types::Message:0x00007fb1efc264a8
 @audio=nil,
 @author_signature=nil,
 @caption=nil,
 @channel_chat_created=nil,
 @chat=
  #<Telegram::Bot::Types::Chat:0x00007fb1efc25c88
   @all_members_are_administrators=true,
   @description=nil,
   @first_name=nil,
   @id=-101746809,
   @invite_link=nil,
   @last_name=nil,
   @photo=nil,
   @pinned_message=nil,
   @title="Home chat",
   @type="group", # for direct messages it would be "private"
   @username=nil>,
 @contact=nil,
 @date=1509222289,
....

Maybe I can use it somehow.

ivanovaleksey avatar Oct 28 '17 20:10 ivanovaleksey

@GanjMonk hmmm can you show us your source code ?(i mean a little bit ...) maybe you typed something wrong .. because i had this problem before and that cause i was banned from telegram and i couldn't even make an channel and i said to my friend to make a bot for me and it worked for me

eVanilla avatar Oct 29 '17 11:10 eVanilla

@eVanilla, sure.

This code doesn't work if command sent from Group Chat /start@bot_name

Telegram::Bot::Client.run(token, logger: Logger.new($stdout)) do |bot|
  begin
    bot.listen do |message|
      case message.text
       when '/start'
         message_text = "Hi #{message.from.first_name}, here is a list of commands: \n
        /calls - _List of calls_ \n
        /duty - _Duty list_ \n
        /requests - _Requests statistic_"
        bot.api.sendMessage(chat_id: message.chat.id, text: message_text, parse_mode: 'Markdown')

This code works if command sent from Group Chat /start@bot_name

Telegram::Bot::Client.run(token, logger: Logger.new($stdout)) do |bot|
  begin
    bot.listen do |message|
      case message.text
       when '/start', '/start@bot_name'
         message_text = "Hi #{message.from.first_name}, here is a list of commands: \n
        /calls - _List of calls_ \n
        /duty - _Duty list_ \n
        /requests - _Requests statistic_"
        bot.api.sendMessage(chat_id: message.chat.id, text: message_text, parse_mode: 'Markdown')

GanjMonk avatar Oct 30 '17 17:10 GanjMonk

@GanjMonk hmmm weird... use this send_message instead of this sendMessage

eVanilla avatar Oct 31 '17 11:10 eVanilla

@eVanilla it works the same. As @ivanovaleksey said it's up to developer how to trigger on a message, so I think we can close this issue. Thx for help.

GanjMonk avatar Nov 05 '17 18:11 GanjMonk

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Feb 19 '23 15:02 github-actions[bot]