Created
May 21, 2017 10:23
-
-
Save PandaWhoCodes/87cf9ddb3b2a7944895e04a4d84491d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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