Sending files with your response
The Poe API allows you to send attachments with your bot response. When using the fastapi_poe library, send file attachments with your bot response by calling post_message_attachment
within the get_response
function of your bot.
Parameters
message_id - the message id associated with the current
QueryRequest
object being processed. Important: This must be the request that is currently being handled byget_response
. Attempting to attach files to previously handled requests will fail.
Additionally, the following must be provided
download_url - provide a url to a file that will be attached to the message.
OR
file_data - the contents of the file to be uploaded. This should be a bytes-like or file object.
filename - the name of the file to be attached.
Example
In this example, the bot will take the input from the user, write it into a text file, and attach that text file in the response to the user. Copy the following code into a file called main.py
(you can pick any name but the deployment commands that follow assume that this is the file name). Change the access_key
stub with your actual key that you can generate on the create bot page.
To learn how to setup Modal, please follow Steps 1 and 2 in our Quick start. If you already have Modal set up, simply run modal deploy main.py
. Modal will then deploy your bot server to the cloud and output the server url. Use that url when creating a server bot on Poe.
Notes
The
access_key
should be the key associated with the bot sending the response. It can be found in the edit bot page.It does not matter where
post_message_attachment
is called, as long as it is within the body ofget_response
. It can be called multiple times to attach multiple (up to 20) files.A file should not be larger than 50mb.
Last updated