How to send rich responses from webhook to Dialogflow Messenger
Recently, I got this question on YouTube:
i have added rich responses code in my dialogflow fulfillment. but when i am testing with dialogflow messanger integration, it is not diaplaying any images, cards on dialogflow messanger. Can you tell me what version i need to use?
Based on the question, I suppose this person is using the Dialogflow fulfillment library.
I recommend people avoid using the fulfillment libraries for Dialogflow unless they are building a voice bot. Since this question is about Dialogflow Messenger, it is recommended that you don’t use the fulfillment library.
There are three reasons why I recommend you avoid the fulfillment library:
a) it makes things unnecessarily opaque
b) the fulfillment library is rarely up to date with the latest features
c) if something in the fulfillment library doesn’t work, you will end up doing MUCH MORE work than if you had just avoided it in the first place
So what do I recommend instead?
I suggest simply understanding the JSON format of the response and constructing it in your code. This way, it is much easier to maintain over time.
The steps are fairly straight forward:
1 First type out the appropriate JSON inside your Custom Payload block (i.e. first hard code the response)
2 Trigger the intent in the Dialogflow Messenger
3 From the History module, get the JSON which was sent as a response
4 Paste this JSON into your webhook response generator code (and make suitable updates so it is dynamic)
You can get some sample code for a Python webhook here.