Unable to trigger event from webhook - api.ai - webhooks

I need your help with the using of events for communication from webhook to demo chat (https://snag.gy/6tfGEZ.jpg) of api.ai. I have already test in telegram too and it does no work either.
My flow is the following:
The user request something from the api.ai web demo chat. for instance: “Hi, I need my access code”
Api.ai gets the intent and send it to my webhook.
My webhook starts an asynchounous operation to process user request (it could take more than 6 seconds) and returns “We are processing your request please wait a few seconds” to api.api therefore the user will see that message in demo chat.
After the asynchrounous process has been finished the next step will be call POST https://api.api.ai/api/query?v=20150910 with body
{
"event": {
"name": "result_event",
"data": {
"code": "ABDDRR787545HHTTU4545454"
}
},
"timezone": "America/New_York",
"lang": "en",
"sessionId": "a77875da-4bd5-db26-dce2-e42439d4fbde"
}
result_event already exists inside an Intent that contains the response “Your request was processed. Here your code: $code”.
The idea here is the user get the respond to his request for instance: “Your request was processed. Here your code: ABDDRR787545HHTTU4545454”
Althought I get a successfully respond of (https://api.api.ai/api/query) called from my webhook the user don’t get any response in the demo chat.
This is the screen (https://snag.gy/qN3tTC.jpg) of the intent with my event in api.ai.
What do you think I’m doing bad ?
Thanks in advance

Events in API.AI are calling methods for a specific intent. it does not trigger anything so you can not get any triggered for you web-demo bot.
this will work if you can make a custom html bot where you can call events endpoint to get the json data and show it in your html bot.

Related

MS Bot Framework Direct Line API 3.0: Get starting message

I published a bot using the Azure bot framework to the Azure cloud servers, and made an application that uses the Direct Line API 3.0 to send user responses and receive bot messages through HTTP requests. Everything works except that I'm not sure how to get the starting message of the bot at the start of the conversation. I open the conversation with the /v3/directline/conversations endpoint, but I'm not sure how to receive the first message of the bot (that is normally sent without any user interaction). A message request after opening the conversation doesn't include any bot responses, but the next message request after sending the first user input includes the first two messages of the bot (starting message and response to the user).
EDIT: From reading this I came to the conclusion that it will be easier to just use a custom event as a trigger for the welcome message. I updated my bot as follows to reflect this within bot composer, adding a new CUSTOM event trigger with a test response message:
However, I still can't seem to trigger this event via the Direct Line API. Currently, I send a request as follows, following the event activity structure:
{
"type": "event",
"channelId": "directline",
"from": { "id": "UnityUserId", "name": "Unity User 1" },
"value": "test",
"name": "welcome"
}
I then get a response with ID, normally indicating that the request was successfull. However, upon requesting the bot response messages, I get the following:
{
"activities": [
{
"type": "event",
"id": "5FZsHpWBxm1hjhWQYY7gr-eu|0000000",
"timestamp": "2022-04-09T14:39:15.90169Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "UnityUserId",
"name": "Unity User 1"
},
"conversation": {
"id": "5FZsHpWBxm1hjhWQYY7gr-eu"
},
"value": "test",
"name": "welcome"
}
],
"watermark": "0"
}
Indicating that the bot has no responses, which doesn't seem quite right when looking at the bot composer screenshot above. Is there something wrong with my current method?
Regards
The onMembersAdded event usually does the trick. Sample code is in https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-send-welcome-message?view=azure-bot-service-4.0&tabs=csharp
I thought I remembered seeing the bot's welcome message when using Direct Line, so I tried to quickly repro it again. I connected a simple echo bot via Direct Line. Then I created a conversation, sent a simple message, and then retrieved all activities (all via REST calls), and the bot's welcome message was indeed present in the response, as you can see in this screenshot:
Perhaps you should use these Direct Line 3.0 API reference docs as opposed to the one you linked above. I followed these steps using the basic Echo bot sample, Postman, and a bot resource in Azure for simple and easy testing, but you could use a full application if you wish.

Is it possible for a slack bot to edit the message on basis of a emoticon?

I want my slack bot to edit the original message (basically modify it).To trigger bot i would like to use an emoticon.
so the flow would be user post the message -> if user wants to use bot press a reaction -> once bot is triggered modify or edit the message with the custom content of bot.
for trigger i think this the API i would need https://api.slack.com/methods/reactions.get but is this even possible?
The api you have mentioned is for fetching the reactions associated with a message/post.
What you actually need is an event to be captured when a reaction is added to the message.
Here is the api that solves the purpose:
https://api.slack.com/events/reaction_added
You can now implement the business logic based on the event payload.
Sample Payload:
{
"type": "reaction_added",
"user": "U024BE7LH",
"reaction": "thumbsup",
"item_user": "U0G9QF9C6",
"item": {
"type": "message",
"channel": "C0G9QF9GZ",
"ts": "1360782400.498405"
},
"event_ts": "1360782804.083113"
}
To update the message, you can use chat.update api:
https://api.slack.com/methods/chat.update
you'll need : token: 'bot token' or 'user token' with required chat:write scope channel & timestamp details : you can find in payload of 'reaction_added' payload.
Note:
You cannot edit a message sent by another user, unless you have the 'User token'. https://api.slack.com/authentication/token-types#user

Integrate Dialogflow with Actions on Google with intents using Fulfillment

When I try to interact with Actions on Google it does not respond when the intent has Fulfillment active.
I receive this error in the logs of Google Cloud Platform:
MalformedResponse: Failed to parse Dialogflow response into AppResponse because of empty speech response
My webhook is responding with a follow-up event input. Here is the response from my API:
{
"followupEventInput": {
"name": "campo-harmonico-found",
"languageCode": "pt-BR",
"parameters": {
"campo-harmonico": "campo harmônico de dó maior ou campo harmônico de ré maior"
}
}
}
The Intent that should call my webhook:
The Intent that should be called after webhook respond:
What is wrong?
I'm not entirely sure what the problem is, but two things jump out at me.
Your campo-harmonico-found Intent has both Training Phrases and an Event set. You should only have one or the other. I would expect that the Event would take priority, but this could be confusing Dialogflow.
It isn't clear that you need to use followupEventInput at all. If your purpose is to just reply with this message - you can just reply with the message from the acorde Intent Handler. Most of the time we don't need to use Followup Events, we should just return the reply that we want from the Intent handler itself.

Directline API message to Microsoft Bot

I have created the bot in azure services using LUIS, which used as chatbot and can create conversations using dialogs.
At some point, I am trying to push messages to chatbot using Direct Line API 3.0, I'm using Postman to send the messages to bot.
I followed the instructions from this page, https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-send-activity?view=azure-bot-service-4.0
I'm able to send message to the conversation as bot, below is the image I sent message from Postman and got successful response.
But my issue is, after the message is sent, the bot tries to analyse even though it's not user message. Bot starts to send message from default message handler like below,
Even after sending the message successfully, my bot triggers the default message handler, which is expected only to happen for user messages but not for bot messages.
Also, I have checked with webchat channel, which it doesn't trigger this default message handler. This is happening only in DirectLine API, can anyone help me on this.
Instead of sending the message as type "message", you should send it as "event".
This way your MessagesController will see it as an ActivityType of Event instead of Message and you can process however you want without spaghettifying your actual message handling
If you want to send different kinds of event to make it even easier, then you can 'name' you event by supplying the 'name' field with a value in your json.
Third, if you need to include data with the message, you would supply a value in the 'value' field of your json.
The github page for the standard webchat client has some great information on sending events. It might shed a bit more light on the json.
You can read more about the 'event' activity type here
You message json would look something more like this:
{
"type": "event",
"from": {
"id": "user1"
},
"name": "theEvent",
"value": "someDataMyBotNeeds"
}

In a chatbot conversation using dialogflow, Is there a way to make the bot speak first?

Is it possible to format a conversation so that the bot initiates conversation using dialogflow in a web demo integration?
The objective is to say something like “Hi, I’m a bot, I can do x” to establish that it’s a chatbot rather than a human.
Can anyone suggest any idea for this?
You can set a welcome intent, then send a /query request containing an event parameter. Set the event parameter to WELCOME and your chatbot will respond with whatever conversation opening you set.
More info here: https://dialogflow.com/docs/events
If you are using something other than the API for interacting with your Dialogflow agent (Slack, Facebook Messenger, etc.) you will need to add an appropriate event under "intents" in your console (such as the "Facebook Welcome" event).
For interacting with your Dialogflow agent via the API, see below.
In the API interaction quickstart documentation, Dialogflow gives you the SessionClient's detectIntent method for sharing messages with your bot.
Each language has a different solution. But on an abstract level, you want to change the request object that you send to Dialogflow to include a "Welcome" event (no input message required), as Omegastick described.
For example, in Node.js, your request object would look like this:
// The text query request.
const request = {
session: sessionPath,
queryInput: {
event: {
name: "Welcome",
languageCode: languageCode
}
},
};
This assumes you have an appropriate intent set up in your Dialogflow console to handle Welcome events. One is provided by default that you can observe.
You can also add contexts, so that your agent gives a different greeting message based on some condition.

Resources