Telegram command is a away to communicate with your bot.

A command must start with / symbol and may not be longer than 32 characters. We can use latin leters, numbers and underscores. Some examples:

/sayhello
/send_me_a_joke
/plus_two_numbers 8, 7

(Read More)

Register commands

We need to provide a list of commands to the BotFather. Each command is registered with format CommandName - Description. You need a line break to input the next command as example below.

sayhello - Hello your bot
checkbcprice - Check bitcoin price

If you have multi bots, BotFather will ask you to select a bot before input the list of commands for it.

For this tutorial, we only register 1 command /sayhello

Register Commands

chat.py

/sayhello is a very basic command. We don’t need to do anything special except generating a text message to send back.

[...]
@__encode_reply_decorator
@__get_reply_decorator
def __get_command_reply(self):
    commant_text = self.message['text']
    if '/sayhello' in commant_text:
        msg = 'Hi, nice to meet you'
        reply_dict = {
            'text': msg.encode('utf-8')
        }
    else:
        msg = 'I know this command. Let me think...'
        reply_dict = {'text': msg.encode('utf-8')}
    return 'sendMessage', reply_dict

To check for a command message, we compare MessageEntity type value with bot_command.

def get_reply(self):
    if self.message:
        if 'entities' in self.message:
            for entity in self.message['entities']:
                if entity['type'] == 'bot_command':
                    return self.__get_command_reply()
        # if not command reply, check for other replies
        if 'sticker' in self.message:
            return self.__get_sticker_reply()
        elif 'text' in self.message:
            return self.__get_text_reply()
        else:
            return self.__get_default_reply()
    return None, None
[...]