2016-10-12 6 views

答えて

0

'payload'フィールドは、このペイロードを持つポストバックが受信されるたびにアクションを呼び出すことができるユーザー定義フィールドです。

例えば、ボットに「ホーム」と「連絡先」の2つのボタンを含む永続的なメニューを作成すると、それぞれのペイロードはボタンの名前と同じになります。ユーザが「ホーム」ボタンをクリックすると、ペイロード「ホーム」とともにポストバックが送信されます。その場合、ユーザーをボットの「ホーム」部分に移動させるアクションを作成することができます。ポストバックとペイロードの詳細について

、に行く: https://developers.facebook.com/docs/messenger-platform/send-api-reference/postback-button https://developers.facebook.com/docs/messenger-platform/webhook-reference/postback-received

は、ポストバックを処理し、あなたのメインの「ポスト」関数で関数を作成することを確認してください。以下のコードは、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 ### 
関連する問題