Can a webhook server have no response? - dialogflow-es

I have a dialogflow implementation using Google assistant, a nodeJS server to serve the webhook calls. Some of the user intents are empty phrases, and they do not need any response from webhook server. However, the webhook must be called with every user sentence.
Can the webhook response return an empty response and not crash while doing so?
The server returns the response in predefined JSON format known to google assistant. When I set this response to NULL OR when I set the payload part of this response to BLANK, the application crashes.
var simpleChatResponse = {
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
]
}
}
},
"outputContexts": [
]
};
Actual results: "myAgent1 is not responding" and the application crashes.

No, you can not send an empty response. As the docs state:
The first item in a rich response must be a simple response.

Related

aws lex v2 dynamic fulfillment from backend

Context
I'm using aws lex V2 and I have already set up a flow so that the user can make an appointment. The thing is that I would like to return (dynamic values) to the user something like:
Expected result
use dynamic values from the backend
ex:
Your appointment has been confirmed. Please keep the following code: {{appointment_code}} when you show up to the interview.
Actual Result
ex:
Your appointment has been confirmed.
When you set up the fulfillment output in aws lex v2, you defined the "static" content of the response, or add the value of the slots using {slotName} in the sentence. No matter what a set my message content from my backend response. i always get the response configure from the aws lex console, but not from the backend.
some code
The response that I'm using after i get all the necessary slots and generate the appointment "code reference" is the following:
function close(sessionAttributes, message) {
return {
"sessionState":{
sessionAttributes,
"dialogAction": {
"type": 'Close',
},
"intent": {
"name": "PetitionsIntent",
"state": "Fulfilled"
},
"messages": [
{
"contentType": "PlainText",
"content": `cool, the apointment code is ${ap_code}`,
}
],
}
};
}
The code works and the intent is fulfilled, but I get the response from the pre-defined lex console(image above) and not from the backend response.
Is there a way to overwrite the predefined output and use the lambda response instead?
What am I missing?
It would appear that your Lambda function has not been invoked.
Clicking the Advanced options button under your fulfillment message will slide in a menu from the right.
Ensure that you've checked the Use a Lambda function for fulfillment option under the Fulfillment Lambda code hook heading.
This assumes that you have correctly configured your bot to make use of a Lambda function.
Also note that Lex will use a different value for invocationSource to denote that all slots have been fulfilled. So your Lambda function will need to look out for FulfillmentCodeHook instead of DialogCodeHook.

How can i get the call-sid from response of callback in twilios AddOn's "IBM Watson"

We enable the Twilios AddOn "IBM Watson Speech to Text" for recording transcribe.and we set our server webhook while enabling the addon. Now twilio calling webhook once call is completely done. after completing call twilio give response in that webhook In Nodejs.For handling that call response we need "Call Sid".In webhook response we cannot get "callSid".So how we can identify that response is for this particular call...?
anyone help me to how can find call-sid in response?
Callback response is
{
"status": "successful",
"message": null,
"code": null,
"results": {
"ibm_watson_speechtotext": {
"request_sid": "**************",
"status": "successful",
"message": null,
"code": null,
"payload": [{
"content_type": "application/json",
"url": "*************/Data"
}],
"links": {
"add_on_result": "***********/Accounts/********/Recordings/**********/AddOnResults/******",
"payloads": "https://api.twilio.com/2010-04-01/Accounts/******/Recordings/*******/AddOnResults/******/Payloads",
"recording": "https://api.twilio.com/2010-04-01/Accounts/******/Recordings/*******"
}
}
}
}
Thank you for help
When you get the Add-on result it comes as part of the Twilio voice webhook, with all the normal request parameters as well as an extra AddOns parameter which contains the JSON that you have shared above.
Webhook requests from Twilio are in the format application/x-www-form-urlencoded and then within the AddOns parameter the data is a JSON string. In a (Ruby-like) pseudo code, you can access the call sid and the add on data like this:
post "/webhook" do
call_sid = params["CallSid"]
add_on_json = params["AddOns"]
add_on_data = JSON.parse(add_on_json)
# return TwiML
end

How can I get the phone number from Twilio in fulfillment dialogflow

I'm working in a whastapp bot between Twilio and Dialogflow. In one of the intents, I'm sending media files from dialogflow to the user. Here it's the problem, now it's working with my mobile number hardcoded, but I need to access to the user phone number in each case to send the media file.
I develop this in fulfillment dialogflow, inline editor, using some nodejs code, but there I can't access to the user number.
Fulfillment node js
function sendAudioMensaje(agent) {
client.messages.create({
body: 'Body message',
to: 'whatsapp:+34---------', // Text to this number
from: 'whatsapp:+14155238886', // From a valid Twilio number
mediaUrl: 'https://demo.twilio.com/owl.png'
}).then((message) => agent.add(message.sid));
}
I expect that the message would be sent to the current number in each conversation
Twilio developer evangelist here.
As far as I can tell, the Dialogflow webhook request comes with a originalDetectIntentRequest property in the JSON. This contains a OriginalDetectIntentRequest object, which has a payload property that contains the original request.
I'd start by logging the contents of the webhook request to see what is fully available to you though.
Let me know if that helps at all.
In the payload of the OriginalDetectIntent request you will see a JSON like this in the webhook if it's enabled.
{
"source": "twilio",
"data": {
"SmsSid": "",
"Body": "",
"SmsStatus": "received",
"MessageSid": "",
"ApiVersion": "2010-04-01",
"From": "",
"AccountSid": "",
"NumMedia": "0",
"To": "",
"SmsMessageSid": "",
"NumSegments": "1"
}
}

Cannot fetch internet message headers for some emails

I'm using the Microsoft Graph Client for Node.js to fetch email messages. I'm only interested in the headers. The code is working, but recently I got some errors in fetching internetMessageHeaders via the API.
For some messages, the API doesn't return any data for this field (and the code wasn't checking for this, hence the errors).
I tried to manually run the queries using POSTMAN. Using ?$select=internetMessageHeaders as a query param to only fetch the headers. If I remove the query param, I can fetch the message normally (body, etc.).
I haven't been able to find anywhere in the docs why this would happen.
Any ideas on what it's happening?
Edit: Here is the node.js code I am using
const MicrosoftGraphClient = require("#microsoft/microsoft-graph-client").Client
async function fetchEmailMessageHeaders(id, credentials) {
let client = MicrosoftGraphClient.init({
authProvider: callback => callback(null, credentials.access_token)
});
let req = client.api(id).select("internetMessageHeaders");
let message = await req.get();
return message.internetMessageHeaders;
}
Sample output (value of message var):
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('156751349d3cc68b')/messages(internetMessageHeaders)/$entity",
"#odata.etag": "W/\"CQAAABYAAABcr9US8aH2RIGaOGQZwDg3AAKyfdpk\"",
"id": "AQMkADAwATM0MDAAMS1hZWIxLThjZmYALTAwAi0wMAoARgAAA3wcQrEUgfhHoZ0BD2jmyXYHAFyv1RLxofZEgZo4ZBnAODcAAAIBDAAAAFyv1RLxofZEgZo4ZBnAODcAArJaPEcAAAA=",
"internetMessageHeaders": [
{
"name": "Received",
"value": "from BY2NAM01HT225.eop-nam01.prod.protection.outlook.com (2603:10a6:803:118::39) by VI1PR0301MB2221.eurprd03.prod.outlook.com with HTTPS via VE1PR03CA0050.EURPRD03.PROD.OUTLOOK.COM; Wed, 10 Apr 2019 11:41:55 +0000"
}
...
]
}
The problem is that for some emails, the message does not contain internetMessageHeaders.
I am using an inbox subscription to receive events for new email messages from Outlook. When an event is received I use the API to retrieve the message and extract headers from it.
API reference here
Edit2:
Here is an example JSON output of an event that fails to also retrieve headers:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('53e07bf4-bb6a-4a82-a724-37dadfb1cf11')/messages(internetMessageHeaders)/$entity",
"#odata.etag": "W/\"CQAAABQAAADdeU+v2VzbRpZMSJGral7kAAXJkA==\"",
"id": "AAMkADhmMmVmM2NjLWFhNGMtNDBlYy04NzBkLTg5MmU2OWI0ODU4MgBGAAAAAAALg6E-e6CxRLEbZfrhFaDBBwAzAAMgKF1iTp242t34rFy5AAAAAAAOAAB5l_O62bUUTqTLk6KYrl4sAAGrJcjfAAA="
}
It seems internetMessageHeaders are not set when an email is replied to using outlook.office365.com. I'm also not able to see message headers when inspecting the message using Outlook on Mac.

Alexa Intent sends two requests and fails

What I am trying to do:
I have a very simple Alexa Skill which listens for a command word:
{
"intents": [{
"intent": "AffiliateEmpire",
"slots": [
{
"name": "affiliate_action",
"type": "AFFILIATE_ACTIONS"
},
{
"name": "date",
"type": AMAZON.DATE
}
}]
}
The custom slot type is:
AFFILIATE_ACTIONS commissions | earnings | sales | summary
My sample utterances are:
AffiliateEmpire for affiliate {affiliate_action}
AffiliateEmpire get {affiliate_action} for {date}
This communicates with my PHP server where I listen for the request type.
What is the problem?
When I invoke the command word without any intent, it makes a "LaunchRequest" to my server and correctly returns a card and outputSpeech
If I ask for an intent, it makes an IntentRequest to my server but then also sends a SessionEndedRequest.
I handle the IntentRequest and send it a json encoded response along the lines of:
array(
'version' => '1.0',
'response' => array(
'outputSpeech' => array(
'type' => 'PlainText',
'text' => 'Some simple response'
)),
'shouldEndSession' => true,
'sessionAttributes' => array()
));
My Amazon Echo never speaks the Some simple response but instead gives me There was a problem communicating with the requested skill
I had a very similar skill working before this, but cannot see what I am doing wrong.
What I have tried.
I am using php to write a log file for each raw request, json_decoded request and the response I sent back to Amazon. I am also using the testing tool, however this gives me The remote endpoint could not be called, or the response it returned was invalid.. I know it can call my endpoint as I see the log file written to each time.
Why is it calling my intent but then causing an error by ending the session?
Try the SSML for responding the alexa request,
Ex:
{
"version": "1.0",
"response": {
"directives": [],
"shouldEndSession": false,
"outputSpeech": {
"type": "SSML",
"ssml": "<speak>I am going to book a cab for you # your provided time.</speak>"
}
}
}
The error you're getting... endpoint could not be called, or the response it returned was invalid suggests that the json you're sending back to the Alexa service is not formatted correctly. You're receiving the request, which is how it's getting logged. Now, you just need to troubleshoot the response your sending back. It's likely something minor. Here are the docs for the json response format: https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html. If you can share the json output from the php code it would be easier to help troubleshoot.
Also, I believe you need to change to 'shouldEndSession' => false
array(
'version' => '1.0',
'response' => array(
'outputSpeech' => array(
'type' => 'PlainText',
'text' => 'Some simple response'
)),
'shouldEndSession' => false,
'sessionAttributes' => array()
));

Resources