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 Quick Replies #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This wrapper has the following functions:
* send_text_message(recipient_id, message)
* send_message(recipient_id, message)
* send_generic_message(recipient_id, elements)
* send_quick_reply(recipient_id, text, type, title, payload, img_url)
* send_button_message(recipient_id, text, buttons)
* send_attachment(recipient_id, attachment_type, attachment_path)
* send_attachment_url(recipient_id, attachment_type, attachment_url)
Expand Down Expand Up @@ -91,14 +92,15 @@ bot.send_image_url(recipient_id, image_url)

* Structured Messages
* Receipt Messages
* Quick Replies
* Airlines
* Tests!

### Example

![Screenshot of Echo Facebook Bot](https://cloud.githubusercontent.com/assets/68039/14516627/905c84ae-0237-11e6-918e-2c2ae9352f7d.png)

![Screenshot of Echo Facebook Bot Quick Reply](https://i.imgur.com/37YkYAY.jpg)

You can find an example of an Echo Facebook Bot in ```examples/```


25 changes: 25 additions & 0 deletions pymessenger/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,31 @@ def send_generic_message(self, recipient_id, elements, notification_type=Notific
}
}, notification_type)

def send_quick_reply(self, recipient_id, text, type, title='', payload='', img_url='', notification_type=NotificationType.regular):
"""Send a quick reply to the specified recipient with specific type of quick reply.
https://developers.facebook.com/docs/messenger-platform/reference/send-api/quick-replies/
Input:
recipient_id: recipient id to send to
text: Text to ask for something
type: content_type. eg: text, location, user_phone_number, user_email
title: Title of quick reply
payload: Postback payload
img_url: Icon URL for quick Reply suggestion
Output:
Response from API as <dict>
"""
return self.send_message(recipient_id, {
"text": text,
"quick_replies":[
{
"content_type":type,
"title":title,
"payload":payload,
"image_url":img_url
}
]
}, notification_type)

def send_button_message(self, recipient_id, text, buttons, notification_type=NotificationType.regular):
"""Send text messages to the specified recipient.
https://developers.facebook.com/docs/messenger-platform/send-api-reference/button-template
Expand Down