.. py:currentmodule:: ehforwarderbot.message
Summary
.. autosummary::
Message
LinkAttribute
LocationAttribute
StatusAttribute
MessageCommands
MessageCommand
Substitutions
Classes
.. autoclass:: ehforwarderbot.message.Message
:members:
.. automodule:: ehforwarderbot.message
:members:
:show-inheritance:
:member-order: bysource
:exclude-members: Message
master: MasterChannel = coordinator.master
slave: SlaveChannel = coordinator.slave['demo.slave']
alice: PrivateChat = slave.get_chat("alice101")
bob: PrivateChat = slave.get_chat("bobrocks")
wonderland: GroupChat = slave.get_chat("thewonderlandgroup")
wonderland_alice: ChatMember = wonderland.get_member("alice101")A message delivered from slave channel to master channel
message = Message( deliver_to=master, chat=wonderland, author=wonderland_alice, # More attributes go here... )
A message delivered from master channel to slave channel
message = Message( deliver_to=slave, chat=alice, author=alice.self, # More attributes go here... )
Data of the quoted message SHOULD be retrieved from recorded historical data. :attr:`.Message.deliver_to` is not required for quoted message, and complete data is not required here. For details, see :attr:`.Message.target`.
You MAY use the :meth:`.Channel.get_message` method to get the message object from the sending channel, but this might not always be possible depending on the implementation of the channel.
message.target = Message(
chat=alice,
author=alice.other,
text="Hello, world.",
type=MsgType.Text,
uid=MessageID("100000002")
)Message ID MUST be the ID from the slave channel regardless of where the message is delivered to.
message.edit = True
message.uid = MessageID("100000003")Text message
message.type = MsgType.Text message.text = "Hello, Wonderland."
Media message
Information related to media processing is described in :doc:`/guide/media_processing`.
The example below is for image (picture) messages. Audio, file, video, sticker works in the same way.
In non-text messages, the
textattribute MAY be an empty string.message.type = MsgType.Image message.text = "Image caption" message.file = NamedTemporaryFile(suffix=".png") message.file.write(binary_data) message.file.seek(0) message.filename = "holiday photo.png" message.mime = "image/png"
Location message
In non-text messages, the
textattribute MAY be an empty string.message.type = MsgType.Location message.text = "I'm here! Come and find me!" message.attributes = LocationAttribute(51.4826, -0.0077)
Link message
In non-text messages, the
textattribute MAY be an empty string.message.type = MsgType.Link message.text = "Check it out!" message.attributes = LinkAttribute( title="Example Domain", description="This domain is established to be used for illustrative examples in documents.", image="https://example.com/thumbnail.png", url="https://example.com" )
Status
In status messages, the
textattribute is disregarded.message.type = MsgType.Status message.attributes = StatusAttribute(StatusAttribute.TYPING)
Unsupported message
textattribute is required for this type of message.message.type = MsgType.Unsupported message.text = "Alice requested USD 10.00 from you. " "Please continue with your Bazinga App."
Substitution
@-reference the User Themself, another member in the same chat, and the entire chat in the message text.
message.text = "Hey @david, @bob, and @all. Attention!" message.substitutions = Substitutions({ # text[4:10] == "@david", here David is the user. (4, 10): wonderland.self, # text[12:16] == "@bob", Bob is another member of the chat. (12, 16): wonderland.get_member("bob"), # text[22:26] == "@all", this calls the entire group chat, hence the # chat object is set as the following value instead. (22, 26): wonderland })
Commands
message.text = "Carol sent you a friend request." message.commands = MessageCommands([ EFBCommand(name="Accept", callable_name="accept_friend_request", kwargs={"username": "carol_jhonos", "hash": "2a9329bd93f"}), EFBCommand(name="Decline", callable_name="decline_friend_request", kwargs={"username": "carol_jhonos", "hash": "2a9329bd93f"}) ])