2016-10-12 3 views

답변

0

'payload'필드는이 페이로드가있는 포스트 백이 수신 될 때마다 작업을 호출 할 수있게 해주는 사용자 정의 필드입니다.

예 : 봇에 '홈'과 '연락처'버튼이 두 개있는 영구 메뉴를 만들고 각 메뉴의 페이로드가 버튼의 이름과 같습니다. 사용자가 '홈'버튼을 클릭하면 페이로드가 '집'으로 다시 게시됩니다. 이 경우 사용자를 봇의 '집'부분으로 이동시키는 작업을 만들 수 있습니다. https://developers.facebook.com/docs/messenger-platform/send-api-reference/postback-button https://developers.facebook.com/docs/messenger-platform/webhook-reference/postback-received

가 포스트 백을 처리하는 주요 '포스트'기능에서 함수를 작성해야합니다 :

는 포스트 백 및 페이로드에 대한 자세한 내용은로 이동합니다. 아래의 코드는 파이썬의 봇 자습서에서 얻은 것입니다.

# 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 ###