Skip to content

Instantly share code, notes, and snippets.

@DanyF-github
Created March 24, 2022 10:53
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 DanyF-github/2a854089c5105d41466cdc82dcc43a40 to your computer and use it in GitHub Desktop.
Save DanyF-github/2a854089c5105d41466cdc82dcc43a40 to your computer and use it in GitHub Desktop.
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