Skip to content

Instantly share code, notes, and snippets.

@benbridts
Created May 13, 2017 15:00
Show Gist options
  • Save benbridts/77a46ff2fc5a617b06b08b1da5d594e3 to your computer and use it in GitHub Desktop.
Save benbridts/77a46ff2fc5a617b06b08b1da5d594e3 to your computer and use it in GitHub Desktop.
Script to send messages to alexa
import requests
import sys
# Configuration, you need to capture this from a request made by the Amazon Alexa App
# Host, conversation_id and sender appear to be static
host = ''
conversation_id = ''
sender = ''
# ubid_main and at_main change over time, so you will need to recapture them from time to time
ubid_main = ''
at_main = ''
def send_message(message):
# The app sends more cookies, but this is the minimum you need to send
cookies = {
'session_id': '', # can be any value?
'ubid-main': ubid_main,
'x-main': '', # can be any value?
'at-main': at_main,
}
url = 'https://{host}/users/{sender}/conversations/{conversation_id}/messages'.format(host=host, sender=sender, conversation_id=conversation_id)
# The app sends more data, but this is the minimum you need to send
payload = [{
"conversationId": conversation_id,
"payload":{"text": message},
"type": "message/text",
"sender": sender,
}]
response = requests.post(url, cookies=cookies, json=payload)
if response.status_code != 200:
print("Status code: {0}".format(response.status_code))
print(response.text)
else:
data = response.json()
data["conversationId"] = "redacted"
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Specify a message please")
exit(1)
send_message(' '.join(sys.argv[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment