dialogflow-webhook-response-libary-in-python
dialogflow-webhook-response-libary-in-python copied to clipboard
This library simplifies the JSON response building in Python for Dialogflow.
Dialogflow Fulfillment Webhook Response Library in Python
This library simplifies the JSON response building in Python for Dialogflow fulfillment.
Using this libray you can build the JSON objects with few line.
Supported Platforms - Actions on Google, Facebook Messenger and Telegram
Update - We have published a tutorial to create a basic webhook in Python + Django Dialogflow Tutorial: Create Fulfillment Webhook Using Python + Django which will be useful to setup this library in Python + Django. We have also published a new repo to showcase examples of creating different responses using this library.
How to use
To get started just import all the functions from the library using the following statement
from df_response_lib import *
Supported Responses
Actions on Google
- Simple Response
- Basic Card
- Suggestion Chips
- Link out suggestion
- List Response
- More will be added soon
Facebook and Telegram
- Text Response
- Card Response
- Image Response
- Quick replies
DF-messenger Responses
- Simple response
- Suggestion chips
- Simple title card
- Informative card
- Image
- Small button
- Card with multiple options
- Accordion small card
Dialogflow Fulfillment Responses
- Fulfillment Text
- Fullfillment Messages
- Followup Event Input
- Output Contexts
Actions on Google
Simple Response
simple_response(responses)
responses - list of simple responses
["Text to be displayed", "Text to be spoken", ssml=True|False]
ex.
aog_sr = aog.simple_response([
["Hello", "Hi", False],
["Hey!!", "<speak>Hey</speak>", True]
])
Basic Card
basic_card(title, subtitle="", formattedText="", image=None, buttons=None)
title is the title of card - string
subtitle is the subtitle of the card - string
formattedText is the description of the card - limited markdown
image display image in the card - list
image = [imageUri, accessibilityText]
buttons add buttons to thr card
buttons = [
[button_title, url]
]
ex.
image = ['https://imagepath.com/path.png', 'sample image']
buttons = [
['button_1', 'https://www.google.com/'],
['button 2', 'https://www.facebook.com/']
]
aog_card = aog.basic_card("card title", "card subtitle", "card *description*", image, buttons)
Suggestion Chips
suggestion_chips(suggestions)
suggestions - list of suggestions upto 8 items (one item length upto 25)
suggestions = ['chip1', 'chip2', 'chip3', 'chip4']
ex.
aog_suggestions = aog.suggestion_chips(suggestions)
Link out Suggestion
link_out_suggestion(title, url)
title - Text to be shown in suggestion
url - Link URL
ex.
title = "Link to google"
url = "https://www.google.com/"
aog_los = aog.link_out_suggestion(title, url)
List Select Response
list_select(list_title, list_elements)
list_title - title of the list
list_elements - list of items of the list select
[
['item_title', 'item_description', item_info=['item_key', item_synonyms=['synonym1', 'synonym2'], ['imageURL', 'imageDescription']],
['item2_title', 'item2_description', item_info=['item_key', item_synonyms=['synonym1', 'synonym2'], ['imageURL', 'imageDescription']]
]
ex.
list_elements = [
['item_title', 'item_description', ['item_key', ['synonym1', 'synonym2'], ['imageURL', 'imageDescription']],
['item2_title', 'item2_description', ['item2_key',['synonym1', 'synonym2'], ['imageURL', 'imageDescription']]
]
aog_list = aog.list_select("this is a list', list_elements)
Facebook and Telegram
Text response
text_response(texts)
texts - list of text
['text1', 'text2', 'text3']
ex.
texts = ['text1', 'text2', 'text3']
text_res = fb.text_response(texts)
Quick Replies
quick_replies(title, quick_replies_list)
quick_replies_list - list of quick replies text
['reply1', 'reply2', 'reply3']
ex.
title = "Choose something"
replies= ['reply1', 'reply2', 'reply3']
fb_quick_replies = fb.quick_replies(title, replies)
Image Response
image_response(url)
url - image URL
ex.
url = "https://www.xyz.com/image.png"
fb_image = fb.image_response(url)
Card Response
card_response(title, buttons)
card title - title of the card
buttons - list of buttons
[
['button1', 'hello'],
['button2', 'hello again']
]
ex.
title = "this is a card"
buttons = [
['button1', 'hello'],
['button2', 'hello again']
]
fb_card = fb.card_response(title, buttons)
Dialogflow messenger
Simple Response
wb = web_response()
texts - list of text
['simple response']
ex.
texts = ['simple response']
text_res = wb.simple_response(texts)
Suggestion Chips
suggestion_chips(suggestion_chips_list)
suggestion_chips_list - list of suggestion chips text
['reply1', 'reply2', 'reply3']
ex.
replies= ['reply1', 'reply2', 'reply3']
wb_suggestion_chips = wb.suggestion_chips(replies)
Image Response
image_response(url, accessibility_text)
url - image URL
ex.
accessibility_text = "This is an accessibility text"
url = "https://www.xyz.com/image.png"
wb_image = wb.image_response(url, accessibility_text)
Card Response
card_response(title, sub_title, raw_url, action_link)
title - title of the card
sub_title - sub title of the card
raw_url - URL of image for card
action_link - redirect URL for card
ex.
title = "title"
sub_title = "subtitle"
raw_url = "www.xyz.com"
action_link = "www.abc.com"
wb_card = wb.simple_title_card(title, sub_title, raw_url, action_link)
Informative card
informative_card(title, text_list)
title - title of the card
text_list - list of text to be displayed in the card
ex.
title = "title"
text_list = ["Sample Text1","Sample Text2","Sample Text3"]
informative_card = wb.informative_card(title, text_list)
Small button
small_button(text, url)
text - text for button
url - URL for image to be displayed on the button
ex.
text = "Sample text"
url = "www.xyz.com"
wb_card = wb.small_button(text, url)
Card with multiple options
card_with_multiple_options(data)
data - list of dictionary with title and subtitle for the card
ex.
data = [
{
"title": "title1",
"subtitle": "subtitle1"
},
{
"title": "title2",
"subtitle": "subtitle2"
}
]
wb_card = wb.card_with_multiple_options(data)
Accordion card response
accordion_small_card(title, sub_title, raw_url, text)
title - title of the card
sub_title - sub title of the card
raw_url - URL of image for the card
text - text for the card
ex.
title = "title"
sub_title = "subtitle"
raw_url = "www.xyz.com"
text = "Sample Text"
wb_card = wb.accordion_small_card(title, sub_title, raw_url, text)
Dialogflow Fulfillment Responses
Fulfillment Text
fulfillment_text(fulfillmentText)
fulfillmentText - defult response text ex.
text = "This is a fulfillment text"
df_fft = main_response.fulfillment_text(text)
Fulfillment Messages
fulfillment_messages(self, response_objects)
response_objects - list of supported response (any of the above)
[aog_sr, aog_list, aog_suggestions, fb_text, fb_card]
ex.
res_objects = [aog_sr, aog_list, aog_suggestions]
ff_msgs = main_response.fulfillment_messages(res_objects)
Output Contexts
output_contexts(session, contexts)
session - session Id of the request
contexts - list of contexts
[
['context_name', 'lifespanCount',
{
'paramter_name': 'value'
}
]
]
Followup Event Input
followup_event_input(name, parameters)
name - event name
paramters - event parameters
{
'parameter_name': 'values',
'another_parameter_name': 'values',
}
Main Response
main_response(fulfillment_text, fulfillment_messages=None, output_contexts=None, followup_event_input=None):
fulfillment_text - Fulfillment text object
fulfillment_messages - Fulfillment messages object
output_contextstext - Output contexts object
followup_event_input - Followup event input object
Return this as your main fulfillment response.
We are working to add more responses in the future. Please give your feedback and do contribute if you like.
Developed by Pragnakalp Techlabs - Artificial Intelligence, Machine Learning, Deep Learning, Chatbots Development