Created
March 24, 2022 10:53
-
-
Save DanyF-github/2a854089c5105d41466cdc82dcc43a40 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
django.conf import settings | |
import requests | |
import json | |
import base64 | |
from requests.exceptions import ConnectionError | |
def send_outbound(message, lead_facebook_id): | |
url = settings.VONAGE_MESSAGES_ENDPOINT | |
auth_param = settings.VONAGE_API_KEY + ":" + settings.VONAGE_API_SECRET | |
auth_code = base64.b64encode(auth_param.encode('utf-8')) | |
payload = json.dumps({ | |
"from": { | |
"type": "messenger", | |
"id": settings.FACEBOOK_ID | |
}, | |
"to": { | |
"type": "messenger", | |
"id": lead_facebook_id | |
}, | |
"message": { | |
"content": { | |
"type": "text", | |
"text": message | |
} | |
} | |
}) | |
headers = { | |
'Authorization': 'Basic %s' % auth_code.decode('utf-8'), | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
} | |
try: | |
response = requests.request("POST", url, headers=headers, data=payload) | |
except ConnectionError: | |
return | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment