SendMessageRequest
Both users and bots can use this request. See code examples.
---functions--- messages.sendMessage#983f9745 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?date send_as:flags.13?InputPeer quick_reply_shortcut:flags.17?InputQuickReplyShortcut effect:flags.18?long = Updates
Returns
Updates |
This type can be an instance of either:
UpdateShort | UpdateShortChatMessage |
UpdateShortMessage | UpdateShortSentMessage |
Updates | UpdatesCombined |
UpdatesTooLong |
Parameters
peer | InputPeer | Anything entity-like will work if the library can find its Input version (e.g., usernames, Peer , User or Channel objects, etc.). |
message | string | |
no_webpage | flag | This argument defaults to None and can be omitted. |
silent | flag | This argument defaults to None and can be omitted. |
background | flag | This argument defaults to None and can be omitted. |
clear_draft | flag | This argument defaults to None and can be omitted. |
noforwards | flag | This argument defaults to None and can be omitted. |
update_stickersets_order | flag | This argument defaults to None and can be omitted. |
invert_media | flag | This argument defaults to None and can be omitted. |
allow_paid_floodskip | flag | This argument defaults to None and can be omitted. |
reply_to | InputReplyTo | This argument defaults to None and can be omitted. |
random_id | long | If left unspecified, it will be inferred automatically. |
reply_markup | ReplyMarkup | This argument defaults to None and can be omitted. |
entities | MessageEntity | This argument defaults to None and can be omitted. Otherwise, a list must be supplied. |
schedule_date | date | This argument defaults to None and can be omitted. |
send_as | InputPeer | This argument defaults to None and can be omitted. Anything entity-like will work if the library can find its Input version (e.g., usernames, Peer , User or Channel objects, etc.). |
quick_reply_shortcut | InputQuickReplyShortcut | This argument defaults to None and can be omitted. |
effect | long | This argument defaults to None and can be omitted. |
Known RPC errors
This request can cause 33 known errors:
AuthKeyDuplicatedError | The authorization key (session file) was used under two different IP addresses simultaneously, and can no longer be used. Use the same session exclusively, or use different sessions. |
BotDomainInvalidError | The domain used for the auth button does not match the one configured in @BotFather. |
ButtonDataInvalidError | The provided button data is invalid. |
ButtonTypeInvalidError | The type of one of the buttons you provided is invalid. |
ButtonUrlInvalidError | Button URL invalid. |
ChannelInvalidError | Invalid channel object. Make sure to pass the right types, for instance making sure that the request is designed for channels or otherwise look for a different one more suited. |
ChannelPrivateError | The channel specified is private and you lack permission to access it. Another reason may be that you were banned from it. |
ChatAdminRequiredError | Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group. |
ChatIdInvalidError | Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead. |
ChatRestrictedError | The chat is restricted and cannot be used in that request. |
ChatWriteForbiddenError | You can't write in this chat. |
EntitiesTooLongError | It is no longer possible to send such long data inside entity tags (for example inline text URLs). |
EntityBoundsInvalidError | Some of provided entities have invalid bounds (length is zero or out of the boundaries of the string). |
EntityMentionUserInvalidError | You can't use this entity. |
InputUserDeactivatedError | The specified user was deleted. |
MessageEmptyError | Empty or invalid UTF-8 message was sent. |
MessageTooLongError | Message was too long. |
MsgIdInvalidError | The message ID used in the peer was invalid. |
PeerIdInvalidError | An invalid Peer was used. Make sure to pass the right peer type and that the value is valid (for instance, bots cannot start conversations). |
PollOptionInvalidError | A poll option used invalid data (the data may be too long). |
RandomIdDuplicateError | You provided a random ID that was already used. |
ReplyMarkupInvalidError | The provided reply markup is invalid. |
ReplyMarkupTooLongError | The data embedded in the reply markup buttons was too much. |
ScheduleBotNotAllowedError | Bots are not allowed to schedule messages. |
ScheduleDateTooLateError | The date you tried to schedule is too far in the future (last known limit of 1 year and a few hours). |
ScheduleStatusPrivateError | You cannot schedule a message until the person comes online if their privacy does not show this information. |
ScheduleTooMuchError | You cannot schedule more messages in this chat (last known limit of 100 per chat). |
TimeoutError | A timeout occurred while fetching data from the worker. |
TopicDeletedError | The topic was deleted. |
UserBannedInChannelError | You're banned from sending messages in supergroups/channels. |
UserIsBlockedError | User is blocked. |
UserIsBotError | Bots can't send messages to other bots. |
YouBlockedUserError | You blocked this user. |
You can import these from telethon.errors
.
Example
Please refer to the documentation of client.send_message()
to learn about the parameters and see several code examples on how to use it.
The method above is the recommended way to do it. If you need more control over the parameters or want to learn how it is implemented, open the details by clicking on the "Details" text.
from telethon.sync import TelegramClient from telethon import functions, types with TelegramClient(name, api_id, api_hash) as client: result = client(functions.messages.SendMessageRequest( peer='username', message='Hello there!', no_webpage=True, noforwards=True, update_stickersets_order=True, invert_media=True, allow_paid_floodskip=True, reply_to=types.InputReplyToMessage( reply_to_msg_id=42, top_msg_id=42, reply_to_peer_id='username', quote_text='some string here', quote_entities=[types.MessageEntityUnknown( offset=42, length=42 )], quote_offset=42 ), schedule_date=datetime.datetime(2018, 6, 25), send_as='username', quick_reply_shortcut=types.InputQuickReplyShortcut( shortcut='some string here' ), effect=-12398745604826 )) print(result.stringify())