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

API.AI Richtext handling #42

Merged
merged 3 commits into from
Jul 8, 2017
Merged

API.AI Richtext handling #42

merged 3 commits into from
Jul 8, 2017

Conversation

Maniae
Copy link

@Maniae Maniae commented Jul 6, 2017

Implementation of Richtext in the plugin for api.ai.
From: https://api.ai/docs/reference/agent/query

  • Add your payload in the api.ai console:
    capture d ecran 2017-07-06 a 15 22 14

  • api.ai will generate a richtext of the following format:
    capture d ecran 2017-07-06 a 15 23 56
    (See the link below)

  • The richtext is printed inside the conversation, outside the message wrapper for quick replies:
    capture d ecran 2017-07-06 a 15 18 06
    capture d ecran 2017-07-06 a 15 18 55

  • Clicking on a button will send it to the bot:

capture d ecran 2017-07-06 a 15 28 36

  • Images are also supported, card are not:

capture d ecran 2017-07-06 a 15 34 20

If using webhook, you should send to the plugin a response of the following format:

    {
      "speech": "",
      "messages": [
        {
          "type": 0,
          "speech": "Here it is:"
        },
        {
          "type": 4,
          "payload": {
            "type": 3,
            "imageUrl": "https://assets-cdn.github.com/images/modules/open_graph/github-octocat.png"
          }
        }
      ]
    }

You can actually use it to send richtext from another platform than api.ai, but it follows api.ai standards.

Btw the code used to send the message when clicking on a button is a little hacky (change the input value and perform a click()) because I didn't want to change the scope of the already implemented functions.

@krilor
Copy link
Owner

krilor commented Jul 6, 2017

Wow Tom, great work!

This looks super sweet. I've been wanting to add rich text support. Thank you so much for improving the plugin.

I've just had the time go glance at the code, but it looks just about merge ready 👍 I'll have some time to check it out this weekend. I'll update you then :)

@krilor
Copy link
Owner

krilor commented Jul 7, 2017

Hi again.
I pulled you changes down to my local machine. When trying to use the plugin, my local server responds with 503 Bad gateway on admin-ajax.php.

Did you have any such errors? I'll try to investigate some more tomorrow.

@krilor krilor merged commit 95ba3fe into krilor:master Jul 8, 2017
@krilor
Copy link
Owner

krilor commented Jul 8, 2017

I set up a separate local docker instance to try the changes. And with that, I had no trouble :)

So, I merged your the changes!

BTW: I had to move the css changes into the scss file for them not to get lost. All css changes should be added to the scss files.

Thanks again!

@lucianosilvi
Copy link

Hi, what would be the right JSONPath to get all the "answers" from the response (plain text and rich responses)?
The default $.result.fulfillment.messages[*].speech only extracts the 'speeches' as expected. But I don't guess a path that matches all the posible responses types.
Thanks!

@Maniae
Copy link
Author

Maniae commented Jul 17, 2017

Hi,
when you choose the api.ai integration type in the plugin settings, the right JSONPath is automatically used, and the JSONPath field in the integration tab should be ignored.
The used JSONPath is $.result.fulfillment.messages[?(@["platform"] == null)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants