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
To get started just import all the functions from the library using the following statement
from df_response_lib import *
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
Dialogflow Fulfillment Responses
- Fulfillment Text
- Fullfillment Messages
- Followup Event Input
- Output Contexts
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(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(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(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(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']],
['item2_title', 'item2_description', item_info=['item_key', item_synonyms=['synonym1', 'synonym2']]
]
ex.
list_elements = [
['item_title', 'item_description', ['item_key', ['synonym1', 'synonym2']],
['item2_title', 'item2_description', ['item2_key',['synonym1', 'synonym2']]
]
aog_list = aog.list_select("this is a list', list_elements)
text_response(texts)
texts - list of text
['text1', 'text2', 'text3']
ex.
texts = ['text1', 'text2', 'text3']
text_res = fb.text_response(texts)
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(url)
url - image URL
ex.
url = "https://www.xyz.com/image.png"
fb_image = fb.image_response(url)
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)
fulfillment_text(fulfillmentText)
fulfillmentText - defult response text ex.
text = "This is a fulfillment text"
df_fft = main_response.fulfillment_text(text)
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(session, contexts)
session - session Id of the request
contexts - list of contexts
[
['context_name', 'lifespanCount',
{
'paramter_name': 'value'
}
]
]
followup_event_input(name, parameters)
name - event name
paramters - event parameters
{
'parameter_name': 'values',
'another_parameter_name': 'values',
}
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 Solutions - Artificial Intelligence, Machine Learning, Deep Learning, Chatbots Development