Che cosa è Facebook Chat campo bot payload?

voti
0

Qualcuno può spiegare a me che cosa è il campo 'payload' a facebook chatbot elemento pulsante? Sono nuovo di sviluppo bot. Sarebbe bello se è possibile fornire un esempio troppo.

È pubblicato 12/10/2016 alle 07:44
fonte dall'utente
In altre lingue...                            


1 risposte

voti
1

il campo 'payload' è un campo definito dall'utente che consente di chiamare un'azione ogni volta che viene ricevuto un postback con questo payload.

per esempio; se creo un menu persistente nella mia bot che contiene 2 pulsanti: 'casa' e 'Contatti', e il payload per ciascuno di essi è lo stesso come il nome del pulsante. Quando un utente fa clic sul pulsante 'Home', un postback viene inviato con il carico utile 'Home'. In questo caso è possibile creare un'azione che porta l'utente alla 'Home' parte del bot.

per di più su postback e payload, vai a: https://developers.facebook.com/docs/messenger-platform/send-api-reference/postback-button https://developers.facebook.com/docs/messenger-platform / webhook-riferimento / postback-ricevuto

fare in modo di creare una funzione nella vostra funzione principale 'post' che gestisce il postback. Il codice che segue è da un tutorial bot in Python

# Post function to handle facebook messages
def post(self, request, *args, **kwargs):
    # converts the text payload into a python dictionary
    incoming_message = json.loads(self.request.body.decode('utf-8'))
    # facebook recommends going through every entry since they might send
    # multiple messages in a single call during high load
    for entry in incoming_message['entry']:
        for message in entry['messaging']:
            # check to make sure the received call is a message call
            # this might be delivery, optin, postback for other events

            if 'message' in message:
                pprint(message)
                ### add here the rest of the code that will be handled when the bot receives a message ###

            if 'postback' in message:
                # print the message in terminal
                pprint(message)
                ### add here the rest of the code that will be handled when the bot receives a postback ###
Risposto il 20/10/2016 a 13:59
fonte dall'utente

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more