Skip to content

Instantly share code, notes, and snippets.

@PandaWhoCodes
Created May 21, 2017 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PandaWhoCodes/87cf9ddb3b2a7944895e04a4d84491d2 to your computer and use it in GitHub Desktop.
Save PandaWhoCodes/87cf9ddb3b2a7944895e04a4d84491d2 to your computer and use it in GitHub Desktop.
def send_message(recipient_id, message_text):
#setting the parameters for the request
params = {
"access_token": os.environ["PAGE_ACCESS_TOKEN"]
#another way you can do this is
# "access_token": "YOUR PAGE ACCESS TOKEN"
}
headers = {
"Content-Type": "application/json"
}
data = json.dumps({
"recipient": {
"id": recipient_id
},
"message": {
"text": message_text
}
})
r = requests.post("https://graph.facebook.com/v2.6/me/messages", params=params, headers=headers, data=data)
if r.status_code != 200:
print("Succesfully sent the message")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment