messages.sendMessage #

Sends a message to a chat

Layer 223

updatesTooLong#e317af7e = Updates;
updateShortMessage#313bc7f8 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true id:int user_id:long message:string pts:int pts_count:int date:int fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?long reply_to:flags.3?MessageReplyHeader entities:flags.7?Vector<MessageEntity> ttl_period:flags.25?int = Updates;
updateShortChatMessage#4d6deea5 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true id:int from_id:long chat_id:long message:string pts:int pts_count:int date:int fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?long reply_to:flags.3?MessageReplyHeader entities:flags.7?Vector<MessageEntity> ttl_period:flags.25?int = Updates;
updateShort#78d4dec1 update:Update date:int = Updates;
updatesCombined#725b04c3 updates:Vector<Update> users:Vector<User> chats:Vector<Chat> date:int seq_start:int seq:int = Updates;
updates#74ae4240 updates:Vector<Update> users:Vector<User> chats:Vector<Chat> date:int seq:int = Updates;
updateShortSentMessage#9015e101 flags:# out:flags.1?true id:int pts:int pts_count:int date:int media:flags.9?MessageMedia entities:flags.7?Vector<MessageEntity> ttl_period:flags.25?int = Updates;
---functions---
messages.sendMessage#545cd15a flags:# no_webpage:flags.1?true silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true invert_media:flags.16?true allow_paid_floodskip:flags.19?true peer:InputPeer reply_to:flags.0?InputReplyTo message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.10?int schedule_repeat_period:flags.24?int send_as:flags.13?InputPeer quick_reply_shortcut:flags.17?InputQuickReplyShortcut effect:flags.18?long allow_paid_stars:flags.21?long suggested_post:flags.22?SuggestedPost = Updates;

Parameters #

NameTypeDescription
flags#Flags, see TL conditional fields
no_webpageflags.1?trueSet this flag to disable generation of the webpage preview
silentflags.5?trueSend this message silently (no notifications for the receivers)
backgroundflags.6?trueSend this message as background message
clear_draftflags.7?trueClear the draft field
noforwardsflags.14?trueOnly for bots, disallows forwarding and saving of the messages, even if the destination chat doesn't have content protection enabled
update_stickersets_orderflags.15?trueWhether to move used stickersets to top, see here for more info on this flag »
invert_mediaflags.16?trueIf set, any eventual webpage preview will be shown on top of the message instead of at the bottom.
allow_paid_floodskipflags.19?trueBots only: if set, allows sending up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance.
peerInputPeerThe destination where the message will be sent
reply_toflags.0?InputReplyToIf set, indicates that the message should be sent in reply to the specified message or story.
Also used to quote other messages.
messagestringThe message
random_idlongUnique client message ID required to prevent message resending. See here » for more info on random ID deduplication and updateMessageID mapping.
reply_markupflags.2?ReplyMarkupReply markup for sending bot buttons
entitiesflags.3?Vector<MessageEntity>Message entities for sending styled text
schedule_dateflags.10?intScheduled message date for scheduled messages
schedule_repeat_periodflags.24?intOnce sent, this message will be automatically re-scheduled to be re-sent again this many seconds in the future, see here » for more info on repeating scheduled messages.
send_asflags.13?InputPeerSend this message as the specified peer
quick_reply_shortcutflags.17?InputQuickReplyShortcutAdd the message to the specified quick reply shortcut », instead.
effectflags.18?longSpecifies a message effect » to use for the message.
allow_paid_starsflags.21?longFor paid messages », specifies the amount of Telegram Stars the user has agreed to pay in order to send the message.
suggested_postflags.22?SuggestedPostUsed to suggest a post to a channel, see here » for more info on the full flow.

Result #

Updates

Both users and bots can use this method #

This method can be invoked over a business connection » #

Possible errors #

CodeTypeDescription
400ADMIN_RIGHTS_EMPTYThe chatAdminRights constructor passed in keyboardButtonRequestPeer.peer_type.user_admin_rights has no rights set (i.e. flags is 0).
406ALLOW_PAYMENT_REQUIREDThis peer only accepts paid messages »: this error is only emitted for older layers without paid messages support, so the client must be updated in order to use paid messages. .
403ALLOW_PAYMENT_REQUIRED_%dThis peer charges %d Telegram Stars per message, but the allow_paid_stars was not set or its value is smaller than %d.
400BALANCE_TOO_LOWThe transaction cannot be completed because the current Telegram Stars balance is too low.
400BOT_DOMAIN_INVALIDBot domain invalid.
400BOT_INVALIDThis is not a valid bot.
400BUSINESS_CONNECTION_INVALIDThe connection_id passed to the wrapping invokeWithBusinessConnection call is invalid.
400BUSINESS_PEER_INVALIDMessages can't be set to the specified peer through the current business connection.
400BUSINESS_PEER_USAGE_MISSINGYou cannot send a message to a user through a business connection if the user hasn't recently contacted us.
400BUTTON_COPY_TEXT_INVALIDThe specified keyboardButtonCopy.copy_text is invalid.
400BUTTON_DATA_INVALIDThe data of one or more of the buttons you provided is invalid.
400BUTTON_ID_INVALIDThe specified button ID is invalid.
400BUTTON_TYPE_INVALIDThe type of one or more of the buttons you provided is invalid.
400BUTTON_URL_INVALIDButton URL invalid.
400BUTTON_USER_INVALIDThe user_id passed to inputKeyboardButtonUserProfile is invalid!
400BUTTON_USER_PRIVACY_RESTRICTEDThe privacy setting of the user specified in a inputKeyboardButtonUserProfile button do not allow creating such a button.
400CHANNEL_INVALIDThe provided channel is invalid.
400CHANNEL_MONOFORUM_UNSUPPORTEDMonoforums do not support this feature.
406CHANNEL_PRIVATEYou haven't joined this channel/supergroup.
403CHAT_ADMIN_REQUIREDYou must be an admin in this chat to do this.
400CHAT_FORWARDS_RESTRICTEDYou can't forward messages from a protected chat.
403CHAT_GUEST_SEND_FORBIDDENYou join the discussion group before commenting, see here » for more info.
400CHAT_ID_INVALIDThe provided chat id is invalid.
400CHAT_RESTRICTEDYou can't send messages in this chat, you were restricted.
403CHAT_SEND_PLAIN_FORBIDDENYou can't send non-media (text) messages in this chat.
403CHAT_WRITE_FORBIDDENYou can't write in this chat.
400DOCUMENT_INVALIDThe specified document is invalid.
400EFFECT_CHAT_INVALIDMessage effects can only be used in private 1-on-1 chats, but the caller tried to send a message with an effect to a group or channel.
400ENCRYPTION_DECLINEDThe secret chat was declined.
400ENTITIES_TOO_LONGYou provided too many styled message entities.
400ENTITY_BOUNDS_INVALIDA specified entity offset or length is invalid, see here » for info on how to properly compute the entity offset/length.
400ENTITY_DATE_FORMAT_INVALIDOne of the passed messageEntityFormattedDate objects has an invalid format (i.e. an invalid combination of the format flags).
400ENTITY_DATE_INVALIDOne of the passed messageEntityFormattedDate objects has an invalid date: the allowed value ranges from 0 to the current date plus 1098 days (time()+1098*86400).
400ENTITY_DATE_TOO_LONGThe maximum text span that can be covered by a date entity is 31 UTF-16 code units if any of the date formatting flags is set, or 127 UTF-16 code units without. .
400ENTITY_MENTION_USER_INVALIDYou mentioned an invalid user.
400FROM_MESSAGE_BOT_DISABLEDBots can't use fromMessage min constructors.
400INPUT_USER_DEACTIVATEDThe specified user was deleted.
400MESSAGE_EMPTYThe provided message is empty.
400MESSAGE_TOO_LONGThe provided message is too long.
400MSG_ID_INVALIDInvalid message ID provided.
500MSG_WAIT_FAILEDA waiting call returned an error.
406PAYMENT_UNSUPPORTEDA detailed description of the error will be received separately as described here ».
404PEER_ID_INVALIDThe provided peer id is invalid.
400PEER_TYPES_INVALIDThe passed keyboardButtonSwitchInline.peer_types field is invalid.
400PINNED_DIALOGS_TOO_MUCHToo many pinned dialogs.
400POLL_OPTION_INVALIDInvalid poll option provided.
403PREMIUM_ACCOUNT_REQUIREDA premium account is required to execute this action.
406PRIVACY_PREMIUM_REQUIREDYou need a Telegram Premium subscription to send a message to this user.
400QUICK_REPLIES_BOT_NOT_ALLOWEDQuick replies cannot be used by bots.
400QUICK_REPLIES_TOO_MUCHA maximum of appConfig.quick_replies_limit shortcuts may be created, the limit was reached.
400QUOTE_TEXT_INVALIDThe specified reply_to.quote_text field is invalid.
500RANDOM_ID_DUPLICATEYou provided a random ID that was already used.
400RANDOM_ID_EMPTYRandom ID empty.
400REPLY_MARKUP_INVALIDThe provided reply markup is invalid.
400REPLY_MARKUP_TOO_LONGThe specified reply_markup is too long.
400REPLY_MESSAGES_TOO_MUCHEach shortcut can contain a maximum of appConfig.quick_reply_messages_limit messages, the limit was reached.
400REPLY_MESSAGE_ID_INVALIDThe specified reply-to message ID is invalid.
400REPLY_TO_INVALIDThe specified reply_to field is invalid.
400REPLY_TO_MONOFORUM_PEER_INVALIDThe specified inputReplyToMonoForum.monoforum_peer_id is invalid.
400REPLY_TO_USER_INVALIDThe replied-to user is invalid.
400SCHEDULE_BOT_NOT_ALLOWEDBots cannot schedule messages.
400SCHEDULE_DATE_TOO_LATEYou can't schedule a message this far in the future.
400SCHEDULE_STATUS_PRIVATECan't schedule until user is online, if the user's last seen timestamp is hidden by their privacy settings.
400SCHEDULE_TOO_MUCHThere are too many scheduled messages.
400SEND_AS_PEER_INVALIDYou can't send messages as the specified peer.
420SLOWMODE_WAIT_%dSlowmode is enabled in this chat: wait %d seconds before sending another message to this chat.
400STORIES_NEVER_CREATEDThis peer hasn't ever posted any stories.
400STORY_ID_INVALIDThe specified story ID is invalid.
400SUGGESTED_POST_AMOUNT_INVALIDThe specified price for the suggested post is invalid.
400SUGGESTED_POST_PEER_INVALIDYou cannot send suggested posts to non-monoforum peers.
406TOPIC_CLOSEDThis topic was closed, you can't send messages to it anymore.
406TOPIC_DELETEDThe specified topic was deleted.
400USER_BANNED_IN_CHANNELYou're banned from sending messages in supergroups/channels.
400USER_BOT_TO_BOT_DISABLEDBot-to-bot messaging is disabled because one of the two bots hasn't enabled the Bot to Bot setting in @BotFather.
403USER_IS_BLOCKEDYou were blocked by this user.
400USER_IS_BOTBots can't send messages to other bots.
400WC_CONVERT_URL_INVALIDWC convert URL invalid.
400YOU_BLOCKED_USERYou blocked this user.

Stickers and masks #

Telegram clients support displaying static and animated stickers.

Bots FAQ #

Working with Updates #

How to subscribe to updates and handle them properly.

Styled text with message entities #

How to create styled text with message entities

Scheduled messages #

Telegram allows scheduling messages

Telegram Business #

Users can turn their Telegram account into a business account, gaining access to business features such as opening hours, location, quick replies, automated messages, custom start pages, chatbot support, and more.

Animated message effects #

Telegram allows adding spectacular animated effects to messages you send.

Telegram Stars can be used to pay for sending messages to users, supergroups and channels that have configured paid messages, requiring a payment for every message sent to them.

Telegram Stars #

Telegram Stars are virtual items that allow users to purchase digital goods and services from bots and mini apps inside the Telegram ecosystem, send gifts to content creators on the Telegram platform, and more.

Suggested posts #

Telegram offers a powerful monetization feature to channel administrators: suggested posts.

keyboardButtonCopy #

Clipboard button

Available only in inline keyboards.

When pressed, clients must copy copy_text to the clipboard.

inputKeyboardButtonUserProfile #

Button that links directly to a user profile

Use this constructor to send a keyboardButtonUserProfile button in an inline keyboard.

Channels, supergroups, gigagroups and basic groups #

How to handle channels, supergroups, gigagroups, basic groups, and what's the difference between them.

Discussion groups #

Groups can be associated to a channel as a discussion group, to allow users to discuss about posts.

Error handling #

How to handle API return errors correctly.

keyboardButtonSwitchInline #

Button to switch the user to inline mode

Available only in inline keyboards.

When pressed, clients must insert the bot's username and query into the chat input field, triggering an inline query.

If same_peer is set, clients use the current chat. Otherwise, clients prompt the user to select a chat, filtered by peer_types if specified.

Telegram Premium #

Telegram Premium is an optional subscription service that unlocks additional exclusive client-side and API-side features, while helping support the development of the app.

Client configuration #

The MTProto API has multiple configuration parameters that can be fetched with the appropriate methods.

Direct messages to channels #

Telegram supports direct messages to channels, which can also be used to suggest (even paid) channel posts.