View Single Post
Sånn!

Kode

def sendrobotmessage(mottaker,msg,token):
 headers = {'Content-Type': 'application/json',}
 params = (('access_token', '%s' % (token)),)
 data = '{ "messaging_type": "response", "recipient": { "id": "%s" }, "message": { "text": "%s" } }' % (sender,msg)
 response = requests.post('https://graph.facebook.com/v9.0/me/messages', headers=headers, params=params, data=data)
 return(response)

##For å kjøre dette:
#sendrobotmessage("mottaker_id","melding",access_token)
##


buttonslist = []
buttonslist.append({ 'type':'postback', 'title':'Hei', 'payload':'Hei' })
buttonslist.append({ 'type':'postback', 'title':'Heisann', 'payload':'Heisann' })

def sendrobotbutton(mottaker,text,buttons,token):
 headers = {'Content-Type': 'application/json',}
 params = (('access_token', '%s' % (token)),)
 data = '{ "recipient":{ "id":"%s" }, "message":{ "attachment":{ "type":"template", "payload":{ "template_type":"button", "text":"%s", "buttons": %s } } } }' % (mottaker,text,buttons)
 response = requests.post('https://graph.facebook.com/v2.6/me/messages', headers=headers, params=params, data=data)
 return(response)

##For å kjøre dette:
#sendrobotbutton("mottaker_id","Velg et alternativ","%s" % (buttonslist),"Access token")
##
Sist endret av RogerThat; 5. januar 2021 kl. 14:58.