1

I want to set some command on my t-bot, but i cant understand how to do that

var token = "123456....";
var url = "https://api.telegram.org/bot" + token;

function setMyCommands(chat_id, message_id){
  var data = {
    method: "post",
    payload:{
      method: "setMyCommands",
      chat_id: String(chat_id),
      message_id: message_id,      
      parse_mode: "HTML"
    }
  };  
  UrlFetchApp.fetch(url + '/', data);
}

Now, I am doing like if message is "/command" to do so. through following:

function sendMessage(id, text, keyBoard){
  var data = {
    method: "post",
    payload: {
      method: "sendMessage",
      chat_id: String(id),
      text: text,
      parse_mode: "HTML",
      reply_markup: JSON.stringify(keyBoard)
    } 
  };
  UrlFetchApp.fetch(url + "/", data);
}


function doPost(e) {
  var contents = JSON.parse(e.postData.contents);
  var id = contents.message.from.id;
  var text = contents.message.text;

  if (text == "/command") {
    sendMessage(id,"someTEXT...") 
    
  }
}

could u pls, also explain what should var data look like and where can I take a form(or structure) of this to apply other methods from telegram bot API

  • Check this https://stackoverflow.com/questions/34457568/how-to-show-options-in-telegram-bot – Vit Aug 14 '22 at 12:44

1 Answers1

3

Pyhton case:

create variables:

BOT_TOKEN = '12324'
BOT_COMMANDS= [{"command":"a", "description":"aaa"},{"command":"b","description":"bbb"}]

create the function:

def setMyCommands():
   send_text = 'https://api.telegram.org/bot' + BOT_TOKEN + '/setMyCommands?commands=' + str(json.dumps(BOT_COMMANDS) ) 
   response = requests.get(send_text)

and finnaly execute:

if __name__ == '__main__':
   #getMyCommands()
   setMyCommands()