MCPcopy Index your code
hub / github.com/python-telegram-bot/python-telegram-bot / _send_message

Method _send_message

src/telegram/_bot.py:755–841  ·  view source on GitHub ↗

Protected method to send or edit messages of any type. It is here to reduce repetition of if-else closes in the different bot methods, i.e. this method takes care of adding its parameters to `data` if appropriate. Depending on the bot method, returns either `True` or the me

(
        self,
        endpoint: str,
        data: JSONDict,
        disable_notification: ODVInput[bool] = DEFAULT_NONE,
        reply_markup: "ReplyMarkup | None" = None,
        protect_content: ODVInput[bool] = DEFAULT_NONE,
        message_thread_id: int | None = None,
        caption: str | None = None,
        parse_mode: ODVInput[str] = DEFAULT_NONE,
        caption_entities: Sequence["MessageEntity"] | None = None,
        link_preview_options: ODVInput["LinkPreviewOptions"] = None,
        reply_parameters: "ReplyParameters | None" = None,
        business_connection_id: str | None = None,
        message_effect_id: str | None = None,
        allow_paid_broadcast: bool | None = None,
        direct_messages_topic_id: int | None = None,
        suggested_post_parameters: "SuggestedPostParameters | None" = None,
        *,
        allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
        reply_to_message_id: int | None = None,
        read_timeout: ODVInput[float] = DEFAULT_NONE,
        write_timeout: ODVInput[float] = DEFAULT_NONE,
        connect_timeout: ODVInput[float] = DEFAULT_NONE,
        pool_timeout: ODVInput[float] = DEFAULT_NONE,
        api_kwargs: JSONDict | None = None,
    )

Source from the content-addressed store, hash-verified

753 return result
754
755 async def _send_message(
756 self,
757 endpoint: str,
758 data: JSONDict,
759 disable_notification: ODVInput[bool] = DEFAULT_NONE,
760 reply_markup: "ReplyMarkup | None" = None,
761 protect_content: ODVInput[bool] = DEFAULT_NONE,
762 message_thread_id: int | None = None,
763 caption: str | None = None,
764 parse_mode: ODVInput[str] = DEFAULT_NONE,
765 caption_entities: Sequence["MessageEntity"] | None = None,
766 link_preview_options: ODVInput["LinkPreviewOptions"] = None,
767 reply_parameters: "ReplyParameters | None" = None,
768 business_connection_id: str | None = None,
769 message_effect_id: str | None = None,
770 allow_paid_broadcast: bool | None = None,
771 direct_messages_topic_id: int | None = None,
772 suggested_post_parameters: "SuggestedPostParameters | None" = None,
773 *,
774 allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
775 reply_to_message_id: int | None = None,
776 read_timeout: ODVInput[float] = DEFAULT_NONE,
777 write_timeout: ODVInput[float] = DEFAULT_NONE,
778 connect_timeout: ODVInput[float] = DEFAULT_NONE,
779 pool_timeout: ODVInput[float] = DEFAULT_NONE,
780 api_kwargs: JSONDict | None = None,
781 ) -> Any:
782 """Protected method to send or edit messages of any type.
783
784 It is here to reduce repetition of if-else closes in the different bot methods,
785 i.e. this method takes care of adding its parameters to `data` if appropriate.
786
787 Depending on the bot method, returns either `True` or the message.
788 However, it's hard to tell mypy which methods expects which of these return values and
789 using `Any` instead saves us a lot of `type: ignore` comments
790 """
791 # We don't check if (DEFAULT_)None here, so that _post is able to insert the defaults
792 # correctly, if necessary:
793 if allow_sending_without_reply is not DEFAULT_NONE and reply_parameters is not None:
794 raise ValueError(
795 "`allow_sending_without_reply` and `reply_parameters` are mutually exclusive."
796 )
797
798 if reply_to_message_id is not None and reply_parameters is not None:
799 raise ValueError(
800 "`reply_to_message_id` and `reply_parameters` are mutually exclusive."
801 )
802
803 if reply_to_message_id is not None:
804 reply_parameters = ReplyParameters(
805 message_id=reply_to_message_id,
806 allow_sending_without_reply=allow_sending_without_reply,
807 )
808
809 data.update(
810 {
811 "allow_paid_broadcast": allow_paid_broadcast,
812 "business_connection_id": business_connection_id,

Callers 15

send_messageMethod · 0.95
send_message_draftMethod · 0.95
forward_messageMethod · 0.95
send_photoMethod · 0.95
send_audioMethod · 0.95
send_documentMethod · 0.95
send_stickerMethod · 0.95
send_videoMethod · 0.95
send_video_noteMethod · 0.95
send_animationMethod · 0.95
send_voiceMethod · 0.95
send_locationMethod · 0.95

Calls 4

_postMethod · 0.95
ReplyParametersClass · 0.90
updateMethod · 0.80
de_jsonMethod · 0.45

Tested by

no test coverage detected