Message broadcasting and editing
​
Function
Description
Bot.sendMessage(text)
Send message to current chat
​
Bot.sendMessage("Hello from bot")
Bot.sendMessageToChatWithId(chatid, text)
Send message to chat with id. Current chatid for chat is contained in chat.chatid
​
Bot.sendMessageToChatWithId("45445454521", "Hello users!")
Bot.sendMessageToChat(chat_name, text)
Send message to other chat. The bot must be installed in another chat room
​
sendMessageToChat("OtherTestChat", "Hello to all!")

Do you want broadcast text?

See Bot.runAll command

Do you want broadcast photo, video and etc?

See Bot.runAll command
​
Security
Please note that the user can create a chat with any name and add to it your bot.
Therefore, the function Bot.sendMessageToChatWithId is more preferable than the function Bot.sendMessageToChat.

Message editing

Function
Description
editMessage(value, message_id, options)
edit message with value and message_id
​
Bot.editMessage("new text", 20)
editMessageInChat(chat_id, value, message_id)
edit message with value and message_id in chat
​
Bot.editMessageInChat(10512154, "new text", 25)
message_id - it is unique identificator for all chats of this bot.

Message_id for income messages to bot

For income messages to bot: use request.message_id

Example

1
let msg_id = request.message_id;
2
Bot.editMessage("new text", msg_id)
3
​
4
// also you can store message_id for future editing:
5
User.setProperty("msg_id", msg_id, "integer");
6
// or if you want to edit message from others chats:
7
Bot.setProperty("msg_id" + chat.chatid, msg_id, "integer");
Copied!
Message_id - have unique value for all chats of bot. So we have only one message_id with value "2" and only in one chat.

Message_id for messages from bot

use on_result in options - see this​

Example

in first command:
1
Bot.sendMessage("hello",
2
{on_result: "onMessageSending" }
3
)
Copied!
in command onMessageSending:
1
// You can inspect all result:
2
// Bot.inspect(options)
3
​
4
let msg_id = options.result.message_id;
5
Bot.editMessage("new text", msg_id);
6
​
7
// Also you can save message_id for future:
8
// Bot.setProperty( "MSG-for-edit" + chat.chatid, msg_id, "integer");
Copied!
​

Options for sendMessage, editMessage and sendKeyboard functionals: Reply, Disable Notification, Disable web page preview

You can pass options parameter to any sendMessageXXX, sendKeyboard, editMesage, editMessageInChat andsendInlineKeyboard functions:
1
let options = { disable_notification: true, reply_to_message_id: request.message_id };
2
Bot.sendMessage("Hello from bot", options);
3
Bot.sendMessageToChatWithId("45445454521", "Hello users!", options);
4
Bot.sendKeyboard("about, help,\ncontacts", "send keyboard now", options)
Copied!
Parameter
Type
Description
disable_web_page_preview
Boolean
Disables link previews for links in this message
disable_notification
Boolean
Sends the message silently. Users will receive a notification with no sound.
reply_to_message_id
Integer
If the message is a reply, ID of the original message
is_reply
Boolean
If the message is a reply for previous message
parse_mode
String
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. Default Markdown. Can be Markdown, HTML or null
result_to_bot_property
String
It is preferable to use "on_result". Store result of message sending in bot property with this name. You can read this result later in other commands by Bot.getProperty
on_result
String
Call this command after method with result
​
Last modified 8mo ago