Problem/Motivation

I would like to respond to the Intent with a custom payload/rich-content message in my Drupal/custom_module/src/Plugin/Chatbot/Intent/MyIntent. Something like as shown here: https://cloud.google.com/dialogflow/es/docs/fulfillment-webhook#custom_p...

Also, is it possible to set the Dialogflow-context from the Drupal-plugin?

{
  "fulfillmentMessages": [
    {
      "payload": {
        "richContent": [ // for Dialogflow Messenger integration
          [
            {
              "type": "image",
              "rawUrl": "https://example.com/images/logo.png",
              "accessibilityText": "Example logo"
            }
          ]
        ],
        // custom integration payload here
      }
    }
  ]
}

Comments

dotist created an issue. See original summary.

gambry’s picture

If this is a missing feature, feel free to provide merge request with your suggestion.

Otherwise, you can always subscribe to the api_ai_webhook_event.request event, where you will be able to adjust your response accordingly.
If you use chatbot_api_apiai, make sure your event subscriber has got a higher wait than the one in that submodule.

gambry’s picture

Status: Active » Closed (works as designed)

Also, from a quick look at the code, you should be able to do it from the plugin.

For example with something like:

$this->response->getFulfillment()->add('payload', $whatever);

Let me know. Closing for now.

gambry’s picture

I triple-checked. Messages are not implemented.

So, I can see 3 options:

  1. Fork my repo, implement set/get message and create a Pull Request. Please add tests if you can!
  2. Create your own Fullfilment class, extending DialogFlow\Model\Fulfillment, and override getMessages()
  3. Use an event subscriber as explained on #2
d0t15t’s picture

Category: Support request » Feature request
Status: Closed (works as designed) » Needs review
StatusFileSize
new3.43 KB

I created patches for the SDK and this module in order to support rich-responses and event-responses. https://github.com/gambry/dialogflow-webhook/pull/1

Status: Needs review » Needs work

The last submitted patch, 5: 3333883-rich-response.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gambry’s picture

@dotist thanks for your work. The patch can be accepted as it is, most of the changes are not really needed (all comments, creation of unused variable, dockblock not needed).

+++ b/modules/chatbot_api_apiai/src/IntentResponseApiAiProxy.php
@@ -80,8 +80,17 @@ class IntentResponseApiAiProxy implements IntentResponseInterface {
+  public function setIntentResponse($response, string $type = 'messages') {

This is a risky change of API. If committed, integrations may break until developers upgrade their code.
What about something like setIntentResponse($data, string $type = 'text') {}, with text being the default. So we make this backcompatible?

We need to make sure we don't break things and new code is tested.
I'll comment changes to gambry/dialogflow-webhook in its own PR.

Thanks!

d0t15t’s picture

StatusFileSize
new1.13 KB

Thanks for your feedback @gambry, I've updated the function and cleaned up the patch!

gambry’s picture

@dotist I'll post it in here too, in case you haven't seen it.

Based on your PR, I created this one: https://github.com/gambry/dialogflow-webhook/pull/3
Please have a look if it has got everything you had in mind, so I can merge it and we finish working on this issue.

Thanks!

gambry’s picture

StatusFileSize
new4.84 KB
new0 bytes
gambry’s picture

Status: Needs work » Needs review

Let's kick tests.

gambry’s picture

While tests run, a bit of documentation.

There are two main ways custom payload or event can be added to the fulfilment:
$this->response->getFulfillment()->addMessage()
$this->response->setIntentRespose()

gambry’s picture

StatusFileSize
new4.44 KB
gambry’s picture

StatusFileSize
new611 bytes
new4.53 KB

Fixing the test.

  • gambry committed a91ac891 on 8.x-2.x
    Issue #3333883 by gambry, dotist: Response with custom payload /...
gambry’s picture

Status: Needs review » Fixed

Fixed! Thanks a lot!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.