ptbtest.messagegenerator module

This module provides a class to generate telegram mesages

class ptbtest.messagegenerator.MessageGenerator(bot=None)

Bases: PtbGenerator

Message generator class.

bot

Bot to encode with the messages

Type

ptbtest.Mockbot

Parameters

bot (Optional[ptbtest.Mockbot]) – supply your own for a custom botname

get_channel_post(chat=None, user=None, **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 telegram.Message.

Return type

telegram.Update

get_edited_channel_post(channel_post=None, **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(message=None, **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(id=None, user=None, chat=None, private=True, reply_to_message=None, text=None, entities=None, audio=None, document=None, photo=None, sticker=None, video=None, voice=None, caption=None, contact=None, location=None, venue=None, new_chat_members=None, left_chat_member=None, new_chat_title=None, new_chat_photo=None, delete_chat_photo=False, group_chat_created=False, supergroup_chat_created=False, migrate_to_chat_id=None, migrate_from_chat_id=None, channel_chat_created=False, pinned_message=None, parse_mode=None, channel=False, via_bot=None)

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
  • id (Optional [int]) – The user’s id

  • 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

  • reply_to_message (Optional[telegram.Message) – Messages this one is a reply to

  • text (str) – The text for the message, can make use of markdown or html, make sure to specify with parse_mode

  • entities (Optional[lst(telegram.MessageEntity)]) – when text and parsemode are set this will be filled with the entities in the text. # noqa: E501

  • audio (Optional[telegram.Audio] 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

  • photo (Optional[lst(telegram.PhotoSize) 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

  • video (Optional[telegram.Video or True]) – Either the right object or True to generate one

  • voice (Optional[telegram.Voice or True]) – Either the right object or True to generate one

  • caption (Optional[str 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

  • location (optional[telegram.Location or True]) – Either the right object or True to generate one

  • venue (Optional[telegram.Venue or True]) – Either the right object or True to generate one

  • new_chat_members (Optional[seq(telegram.User)]) – New member(s) 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

  • delete_chat_photo (Optional[True]) – Not integrated

  • group_chat_created (Optional[True]) – Not integrated

  • supergroup_chat_created (Optional[True]) – Not integrated

  • migrate_to_chat_id (Optional[int]) – Not integrated

  • migrate_from_chat_id (Optional[int]) – Not integrated

  • channel_chat_created (Optional[True]) – Not integrated

  • pinned_message (Optional[telegram.Message]) – Pinned message for supergroups

  • parse_mode (Optional[str]) – “HTML” or “Markdown” parses the text and fills entities

  • channel (Optional[str]) – If the message was sent via a channel

  • via_bot (Optional[bool]) – If the message was sent via a bot

Returns

A telegram update object containing a telegram.Message.

Return type

telegram.Update