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 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:

UpdateShortUpdateShortChatMessage
UpdateShortMessageUpdateShortSentMessage
UpdatesUpdatesCombined
UpdatesTooLong

Parameters

peerInputPeerAnything entity-like will work if the library can find its Input version (e.g., usernames, Peer, User or Channel objects, etc.).
messagestring
no_webpageflagThis argument defaults to None and can be omitted.
silentflagThis argument defaults to None and can be omitted.
backgroundflagThis argument defaults to None and can be omitted.
clear_draftflagThis argument defaults to None and can be omitted.
noforwardsflagThis argument defaults to None and can be omitted.
update_stickersets_orderflagThis argument defaults to None and can be omitted.
invert_mediaflagThis argument defaults to None and can be omitted.
reply_toInputReplyToThis argument defaults to None and can be omitted.
random_idlongIf left unspecified, it will be inferred automatically.
reply_markupReplyMarkupThis argument defaults to None and can be omitted.
entitiesMessageEntityThis argument defaults to None and can be omitted. Otherwise, a list must be supplied.
schedule_datedateThis argument defaults to None and can be omitted.
send_asInputPeerThis 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_shortcutInputQuickReplyShortcutThis argument defaults to None and can be omitted.
effectlongThis argument defaults to None and can be omitted.

Known RPC errors

This request can cause 33 known errors:

AuthKeyDuplicatedErrorThe 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.
BotDomainInvalidErrorThe domain used for the auth button does not match the one configured in @BotFather.
ButtonDataInvalidErrorThe provided button data is invalid.
ButtonTypeInvalidErrorThe type of one of the buttons you provided is invalid.
ButtonUrlInvalidErrorButton URL invalid.
ChannelInvalidErrorInvalid 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.
ChannelPrivateErrorThe channel specified is private and you lack permission to access it. Another reason may be that you were banned from it.
ChatAdminRequiredErrorChat 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.
ChatIdInvalidErrorInvalid 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.
ChatRestrictedErrorThe chat is restricted and cannot be used in that request.
ChatWriteForbiddenErrorYou can't write in this chat.
EntitiesTooLongErrorIt is no longer possible to send such long data inside entity tags (for example inline text URLs).
EntityBoundsInvalidErrorSome of provided entities have invalid bounds (length is zero or out of the boundaries of the string).
EntityMentionUserInvalidErrorYou can't use this entity.
InputUserDeactivatedErrorThe specified user was deleted.
MessageEmptyErrorEmpty or invalid UTF-8 message was sent.
MessageTooLongErrorMessage was too long.
MsgIdInvalidErrorThe message ID used in the peer was invalid.
PeerIdInvalidErrorAn invalid Peer was used. Make sure to pass the right peer type and that the value is valid (for instance, bots cannot start conversations).
PollOptionInvalidErrorA poll option used invalid data (the data may be too long).
RandomIdDuplicateErrorYou provided a random ID that was already used.
ReplyMarkupInvalidErrorThe provided reply markup is invalid.
ReplyMarkupTooLongErrorThe data embedded in the reply markup buttons was too much.
ScheduleBotNotAllowedErrorBots are not allowed to schedule messages.
ScheduleDateTooLateErrorThe date you tried to schedule is too far in the future (last known limit of 1 year and a few hours).
ScheduleStatusPrivateErrorYou cannot schedule a message until the person comes online if their privacy does not show this information.
ScheduleTooMuchErrorYou cannot schedule more messages in this chat (last known limit of 100 per chat).
TimeoutErrorA timeout occurred while fetching data from the worker.
TopicDeletedErrorThe topic was deleted.
UserBannedInChannelErrorYou're banned from sending messages in supergroups/channels.
UserIsBlockedErrorUser is blocked.
UserIsBotErrorBots can't send messages to other bots.
YouBlockedUserErrorYou 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,
        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())