Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Text Quick Replies #76

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions pymessenger/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,58 @@ def remove_persistent_menu(self):
)
result = response.json()
return result

def send_text_quick_replies(self, recipient_id, listOfReplies, messageToReplyTo = "Hello, is there anything I can help you with?", listOfPayloads=[]):
"""
Sends a list of text quick replies with an optional message (Default = " ") to send before sending the quick replies
Payload and Message are optional, however, if no payload for a specific reply (i.e. None)
or for all quick replies, the payload will be defined as the reply itself.


https://developers.facebook.com/docs/messenger-platform/send-messages/quick-replies/#text

Output:
Response from API as <dict>
"""
quickRepliesList = []

# If no payloads identified
if len(listOfPayloads) == 0:
for reply in listOfReplies:
quickRepliesList.append({
"content_type":"text",
"title":reply,
"payload":reply
})

# If payloads is identified
else:
for reply, payload in zip(listOfReplies, listOfPayloads):
# if some payload is not identified in the list
if payload == None:
quickRepliesList.append({
"content_type":"text",
"title":reply,
"payload":reply
})
else:
quickRepliesList.append({
"content_type":"text",
"title":reply,
"payload":payload
})

# if the length of payloads is less than replies, then just let the payload for the rest to be just the reply
if len(listOfPayloads) < len(listOfReplies):
for reply in listOfReplies[len(listOfPayloads):]:
quickRepliesList.append({
"content_type":"text",
"title":reply,
"payload":reply
})

return self.send_message(recipient_id, {
"text": messageToReplyTo,
"quick_replies": quickRepliesList
})