ptbtest.messagegenerator module

This module provides a class to generate telegram mesages

class ptbtest.messagegenerator.MessageGenerator(bot=None)

Bases: ptbtest.ptbgenerator.PtbGenerator

Message generator class.

bot

ptbtest.Mockbot – Bot to encode with the messages

Parameters:bot (Optional[ptbtest.Mockbot]) – supply your own for a custom botname
get_channel_post(*args, **kwargs)
Parameters:
  • chat (Optional[telegram.Chat]) – Chat with type=’channel’ to use with this update
  • user (Optional[telegram.User]) – User for the update. None if omitted
  • **kwargs – See get_message
Returns:

A telegram update object containing a :py:class:`telegram.Message.

Return type:

telegram.Update

get_edited_channel_post(*args, **kwargs)
Parameters:
  • channel_post (Optional(telegram.Message)) – The edited_channel_post will the same user, chat and message_id
  • **kwargs – See get_message for the full list
Returns:

A telegram update object containing a telegram.Message.

Return type:

telegram.Update

get_edited_message(*args, **kwargs)
Parameters:
  • message (Optional(telegram.Message)) – The edited_message will have the same user, chat and message_id
  • **kwargs – See get_message for the full list
Returns:

A telegram update object containing a telegram.Message.

Return type:

telegram.Update

get_message(*args, **kwargs)

When called without arguments will return an update object for a message from a private chat with a random user. for modifiers see args.

Notes

whenever a list of telegram.PhotoSize objects is expected but not supplied it will always be a list with two random sizes between 40-400 pixels. These will not be valid file id’s

Parameters:
  • user (Optional[telegram.User]) – User the message is from (m.from_user)
  • chat (Optional[telegram.Chat]) – Chat the message is from (m.chat).
  • private (Optional[bool]) – If the message is private (optionally with the supplied user) default=True
  • text (str) – The text for the message, can make use of markdown or html, make sure to specify with parse_mode
  • parse_mode (Optional[str]) – “HTML” or “Markdown” parses the text and fills entities
  • entities (Optional[lst(telegram.MessageEntity)]) – when text and parsemode are set this will be filled with the entities in the text. # noqa: E501
  • reply_to_message (Optional[telegram.Message) – Messages this one is a reply to
  • forward_from (Optional[telegram.User) – User this message is forwarded from
  • forward_from_chat (Optional[telegram.Chat]) – channel this message is forwarded from
  • forward_date (Optional[int]) – Original sent date
  • forward_from_message_id (Optional[int]) – message id from forwarded channel post.
  • new_chat_member (Optional[telegram.User]) – New member for this chat
  • left_chat_member (Optional[telegram.User]) – Member left this chat
  • new_chat_title (Optional[str]) – New title for the chat
  • new_chat_photo (Optional[lst(telegram.Photosize)] or True) – New picture for the group
  • pinned_message (Optional[telegram.Message]) – Pinned message for supergroups
  • channel_chat_created (Optional[True]) – Not integrated
  • migrate_from_chat_id (Optional[int]) – Not integrated
  • migrate_to_chat_id (Optional[int]) – Not integrated
  • supergroup_chat_created (Optional[True]) – Not integrated
  • group_chat_created (Optional[True]) – Not integrated
  • delete_chat_photo (Optional[True]) – Not integrated
  • venue (Optional[telegram.Venue or True]) – Either the right object or True to generate one
  • location (optional[telegram.Location or True]) – Either the right object or True to generate one
  • contact (optional[telegram.Contact or True]) – Either the right object or True to generate one
  • (Optional[str or True] (caption) – Either the right object or True to generate one
  • voice (Optional[telegram.Voice or True]) – Either the right object or True to generate one
  • video (Optional[telegram.Video or True]) – Either the right object or True to generate one
  • sticker (Optional[telegram.Sticker] or True) – Either the right object or True to generate one
  • photo (Optional[lst(telegram.PhotoSize) or True]) – Either the right object or True to generate one
  • document (Optional[telegram.Document or True]) – Either the right object or True to generate one
  • audio (Optional[telegram.Audio] or True) – Either the right object or True to generate one
Returns:

A telegram update object containing a telegram.Message.

Return type:

telegram.Update