Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dugjason/15be48aa62ba03f92c790e49ff0f2f34 to your computer and use it in GitHub Desktop.
Save dugjason/15be48aa62ba03f92c790e49ff0f2f34 to your computer and use it in GitHub Desktop.
Python script to import message including inline image
# Type: Python3
# Description: Import a message including an inline image to a channel in Front.
# The image is encoded in base64 and included in the message body.
# API Endpoint Documentation: https://dev.frontapp.com/reference/post_channels-channel-id-incoming-messages
import base64
import requests
url = "https://api2.frontapp.com/channels/cha_123/incoming_messages"
with open("image.png", "rb") as image_file:
data = base64.b64encode(image_file.read())
payload = {
"subject": "My message subject",
"body": '<p>My message body</p> <img src="data:image/png;base64, ' + data.decode("utf-8") + '" /><p>Inline image above</p>',
"body_format": "html",
"sender": {
"handle": "sender@example.com",
"name": "Sender Name"
}
}
res = requests.post(
url,
json=payload,
headers={"Authorization": "Bearer YOUR_API_TOKEN"}
)
if res.ok:
print("Upload completed successfully!")
print(res.text)
else:
print("Something went wrong!")
print(res.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment