Sending messages and attachments¶
In the previous section we explored how to retrieve existing chats, or create new ones.
Now we can see how to send messages and attachments through the chat.post()
method.
Sending a text message¶
Sending a text message is as easy as invoking chat.post()
with a string message
argument:
from teamwire_api import Connection
async def send_message(connection):
# find chats with title 'test'
chats = await connection.chats.get_by_title('test')
if len(chats) == 0:
print('no chats found')
return
# get the last matching chat
chat = chats[-1]
# send text message "hello"
await chat.post(message='hello')
with Connection() as connection:
connection.exec_async(send_message(connection))
Sending an attachment¶
The chat.post()
method can also be invoked with
an attachments
argument, which can be either a list of Attachment
objects, or an Attachments
object.
In the general case, we should first create a new Attachments
object
and add attachments to it, then we can send them in the chat.
The following example shows how to send a location attachment:
from teamwire_api import Connection
async def send_message(connection):
# get the target chat
chat = await connection.chats.get_by_thread_id('7MQKchz6wsSzmWTVnppGAc')
if not chat:
print('Chat not found')
attachments = chat.new_attachments()
await attachments.add_location(
name='Munich',
lat=48.1377183,
lon=11.5774404
)
# send the attachment
await chat.post(attachments=attachments)
with Connection() as connection:
connection.exec_async(send_message(connection))
Note
If multiple attachments are added to the Attachments
object, these will
be sent in separate messages by the SDK when invoking chat.post()
Sending an image file¶
Sending images or other kinds of attachments based on binary content is similar. We can for example send a PNG image from a file:
from teamwire_api import Connection
async def send_message(connection):
# get the target chat
chat = await connection.chats.get_by_thread_id('7MQKchz6wsSzmWTVnppGAc')
if not chat:
print('Chat not found')
attachments = chat.new_attachments()
# add image attachment
await attachments.add_gallery('image.png')
# send
await chat.post(attachments=attachments)
with Connection() as connection:
connection.exec_async(send_message(connection))
Sending a base64 encoded image¶
Besides loading asset based attachments from file, attachments can also
be created by directly passing a byte array to the add_*()
methods (where
* stands for 'gallery', 'sound', 'video' and 'file')
from teamwire_api import Connection
import base64
async def send_message(connection):
# get the target chat
chat = await connection.chats.get_by_thread_id('7MQKchz6wsSzmWTVnppGAc')
if not chat:
print('Chat not found')
attachments = chat.new_attachments()
# image data encoded as a base64 string
base64_img = "iVBORw0KGgoAAAANSUhEUgAAAJg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UJlazAsoRKVmBZQiUrsCyh8n/aB/JNqr4rsAAAAABJRU5ErkJggg=="
# convert the string to bytes
b64_bytes = base64_img.encode('utf-8')
# decode the base64 content into a byte array
image_data = base64.decodebytes(b64_bytes)
await attachments.add_gallery(image_data)
await chat.post(attachments=attachments)
with Connection() as connection:
connection.exec_async(send_message(connection))