Invalid response from webhook: Failed to translate JSON to ExecuteHttpResponse - arrays

I have a webhook from my google assistant new actions builder platform. Webhook code is written in the dotnet vs2019. I have followed the webhook request and response format and sample jsons provided in the below links.
https://developers.google.com/assistant/conversational/reference/rest/v1/TopLevel/fulfill#User
https://developers.google.com/assistant/conversational/webhooks#request-json_1
But when I test assistant action, it is failing. Below is request and response json from logs in the google assistant test simulator.Error message just says"Invalid response from webhook: Failed to translate JSON to ExecuteHttpResponse." I don't know why it is not valid. Can someone help me resolving this.
{
"requestJson": {
"handler": {
"name": "agentcube"
},
"intent": {
"name": "",
"params": {
"phone": {
"original": "1234562869",
"resolved": 1234562869
}
},
"query": "1234562869"
},
"scene": {
"name": "Start",
"slotFillingStatus": "FINAL",
"slots": {
"Zip": {
"mode": "REQUIRED",
"status": "SLOT_UNSPECIFIED",
"updated": false,
"value": 37122
},
"Phone": {
"mode": "REQUIRED",
"status": "SLOT_UNSPECIFIED",
"updated": true,
"value": 1234562869
},
"FName": {
"mode": "REQUIRED",
"status": "SLOT_UNSPECIFIED",
"updated": false,
"value": "john doe"
}
},
"next": {
"name": "actions.scene.END_CONVERSATION"
}
},
"session": {
"id": "ABwppHFkFuGBF-UawPmIkxWpkfM1Hb5An7h8KnjR302zukmBoKA1NqDp7DfePGzYsyxT5oy--wg5Jkjj",
"params": {
"Phone": 1234562869,
"FName": "john doe",
"Zip": 37122
},
"typeOverrides": [],
"languageCode": ""
},
"user": {
"locale": "en-US",
"params": {},
"accountLinkingStatus": "NOT_LINKED",
"verificationStatus": "VERIFIED",
"packageEntitlements": [],
"gaiamint": "",
"permissions": [],
"lastSeenTime": "2021-01-28T19:21:28Z"
},
"home": {
"params": {}
},
"device": {
"capabilities": [
"SPEECH",
"RICH_RESPONSE",
"LONG_FORM_AUDIO"
]
}
}
}
Invalid response from webhook: Failed to translate JSON to ExecuteHttpResponse..
{
"responseJson": {
"Session": {
"Id": "ABwppHFkFuGBF-UawPmIkxWpkfM1Hb5An7h8KnjR302zukmBoKA1NqDp7DfePGzYsyxT5oy--wg5Jkjj",
"Params": {
"Phone": 1234562869,
"Zip": 37122,
"FName": "john doe"
}
},
"Prompt": {
"Override": false,
"FirstSimple": {
"Speech": "My webhook response",
"Text": "My response from webhook"
}
},
"Scene": {
"Name": "Start",
"SlotFillingStatus": "FINAL",
"Slots": {
"Phone": {
"Mode": "REQUIRED",
"Status": "SLOT_UNSPECIFIED",
"Updated": true,
"value": 1234562869
},
"FName": {
"Mode": "REQUIRED",
"Status": "SLOT_UNSPECIFIED",
"Updated": false,
"value": "john doe"
},
"Zip": {
"Mode": "REQUIRED",
"Status": "SLOT_UNSPECIFIED",
"Updated": false,
"value": 37122
}
},
"Next": {
"Name": "actions.scene.END_CONVERSATION"
}
}
}
}

Make sure the response that you code is returning is json by checking with a linter, which this seems to checks (i.e. everything inside the ResponseJson {}
Please see my response to a similar issue at https://stackoverflow.com/a/66512370/10537202 to use the webhook playground.

Related

Mock service worker with openApi backend

I am working with MSW and OpenAPI-backend package.
I want to mock the booth browser server and test server.
I have OpenAPI definition available form with I generate generated.ts for RTK Query (out of scope for this question). I want to use OpenAPI spec to use it with OpenAPI Backend and generate MSW rest worker for browser and for test.
Setup is next:
index.tsx
import worker from './mocks/browser';
if (process.env.NODE_ENV === 'development') {
worker.start();
}
mock/browser.ts
import { setupWorker, rest } from 'msw';
import { OpenAPIBackend } from 'openapi-backend';
import type { Document } from 'openapi-backend';
import definition from './api.json';
// create our mock backend with openapi-backend
const api = new OpenAPIBackend({ definition: definition as Document });
api.register('notFound', (c, res, ctx) => res(ctx.status(404)));
api.registerHandler('notImplemented', async (c, req, res) => {
const { status, mock } = await api.mockResponseForOperation(
c.operation.operationId as string
);
return res.status(status).json(mock);
});
api.register('validationFail', (c, res, ctx) =>
res(ctx.status(400), ctx.json({ error: c.validation.errors }))
);
const worker = setupWorker(
rest.get('/*', (req) =>
api.handleRequest({
...req,
path: req.url.pathname,
headers: req.headers.all(),
method: req.method,
body: req.body,
})
)
);
export default worker;
api.JSON
{
"openapi": "3.0.1",
"info": {
"title": "Fetch API",
"description": "Source of truth for Fetch dashboard",
"version": "0.1.5"
},
"paths": {
"/config": {
"get": {
"tags": [
"Configuration"
],
"summary": "Retreive configuration object",
"description": "Returns configuration object (map) containing configuration parameters for UI (Map<String, String>)",
"responses": {
"200": {
"description": "successfull operation",
"content": {
"application/json": {
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "Map serialized to json object.",
"example": {
"FA_COLOR": "red",
"FA_NAME": "fetch"
}
}
}
}
}
}
}
},
"/links": {
"get": {
"tags": [
"Notifications & Links",
"Walking Skeleton"
],
"summary": "List all defined links for hospital",
"description": "Retreives all defined links for hospital. Hospital ID is indirectly obtained from user identity.",
"responses": {
"200": {
"description": "successfull operation",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Link"
}
}
}
}
}
}
}
},
"/kpis": {
"get": {
"tags": [
"KPIS"
],
"summary": "List all KPIs for hospital(s) that current user is managing.",
"description": "Retreives all KPIs available for hospitals that current user is managing.",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/KPI"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"KPI": {
"type": "object",
"properties": {
"id": {
"type": "string",
"enum": [
"revenue",
"labour"
]
},
"hospital_id": {
"type": "string",
"description": "id of hospital that this KPI describes"
},
"goal": {
"type": "number",
"description": "full month goal"
},
"actual": {
"type": "number",
"description": "actual result"
},
"mtd_goal": {
"type": "number",
"description": "month to date goal, so that we can track projected fulfillment of goal."
},
"details": {
"type": "object",
"description": "Semi-structured way of describing details of calculation. Every KPI will potentialiy be described differently."
}
},
"required": [
"id",
"hospital_id",
"goal",
"actual",
"mtd_goal"
]
},
"Link": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "unique id of link"
},
"hospital_id": {
"type": "string",
"description": "id of hospital that this Link is configured for"
},
"title": {
"type": "string",
"description": "human readable title for URL"
},
"description": {
"type": "string",
"description": "Description of current link (alt text , or tooltip)"
},
"url": {
"type": "string",
"description": "Location of external resource"
},
"urgent": {
"type": "boolean",
"description": "Is urgency of notification elevated?"
},
"count": {
"type": "number",
"description": "Actual notification value. How many 'tasks' are waiting manager in external system."
},
"updated_at": {
"type": "integer",
"description": "Date/time of last notification update",
"format": "int64"
},
"children": {
"type": "array",
"description": "Since notifications are possibly presented in hierarchy all children of this notification will be gathered here",
"items": {
"$ref": "#/components/schemas/Link"
}
}
},
"required": [
"id",
"hospital_id",
"title",
"url"
],
"example": [
{
"id": 1,
"hospital_id": "001",
"title": "Link1",
"description": "description of Link1",
"url": "https://www.example.com/link1",
"urgent": true,
"count": 1,
"updated_at": 1631113184221,
"children": [
{
"id": 2,
"hospital_id": "001",
"title": "Link2",
"description": "description of Link2",
"url": "https://www.example.com/link2",
"urgent": true,
"count": 1,
"updated_at": 1631113184221
}
]
},
{
"id": 3,
"hospital_id": "002",
"title": "Link3",
"description": "description of Link3",
"url": "https://www.example.com/link3",
"urgent": false,
"count": 2,
"updated_at": 1631113184221
}
]
}
}
}
}
component.tsx
const { data: links, error, isLoading } = useGetLinksQuery({});
Which is fethcing localhost:3000/links
Error I am getting is:
mockServiceWorker.js:222 [MSW] Uncaught exception in the request handler for "GET http://localhost:3000/links":
Error: Unknown operation
at OpenAPIValidator.validateRequest (http://localhost:3000/static/js/vendors~main.chunk.js:63911:13)
at OpenAPIBackend.<anonymous> (http://localhost:3000/static/js/vendors~main.chunk.js:54246:45)
at async OpenAPIBackend.handleRequest (http://localhost:3000/static/js/vendors~main.chunk.js:54152:22)
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses
getResponse # mockServiceWorker.js:222
async function (async)
getResponse # mockServiceWorker.js:175
handleRequest # mockServiceWorker.js:113
async function (async)
handleRequest # mockServiceWorker.js:112
(anonymous) # mockServiceWorker.js:271
Network tabs give:
Request URL: http://localhost:3000/links
Request Method: GET
Status Code: 500 (from service worker)
Referrer Policy: strict-origin-when-cross-origin
All related to article: https://dev.to/epilot/testing-react-with-jest-and-openapi-mocks-8gc
and https://testing-library.com/docs/react-testing-library/example-intro/
Thank you.
In your OpenApi u don't have any operationId.
You need to setup a unique Id by route.
{
"openapi": "3.0.1",
"info": {
"title": "Fetch API",
"description": "Source of truth for Fetch dashboard",
"version": "0.1.5"
},
"paths": {
"/config": {
"get": {
"tags": [
"Configuration"
],
"operationId": "config",
"summary": "Retreive configuration object",
"description": "Returns configuration object (map) containing configuration parameters for UI (Map<String, String>)",
"responses": {
"200": {
"description": "successfull operation",
"content": {
"application/json": {
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "Map serialized to json object.",
"example": {
"FA_COLOR": "red",
"FA_NAME": "fetch"
}
}
}
}
}
}
}
},
"/links": {
"get": {
"tags": [
"Notifications & Links",
"Walking Skeleton"
],
"operationId": "links",
"summary": "List all defined links for hospital",
"description": "Retreives all defined links for hospital. Hospital ID is indirectly obtained from user identity.",
"responses": {
"200": {
"description": "successfull operation",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Link"
}
}
}
}
}
}
}
},
"/kpis": {
"get": {
"tags": [
"KPIS"
],
"summary": "List all KPIs for hospital(s) that current user is managing.",
"description": "Retreives all KPIs available for hospitals that current user is managing.",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/KPI"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"KPI": {
"type": "object",
"properties": {
"id": {
"type": "string",
"enum": [
"revenue",
"labour"
]
},
"hospital_id": {
"type": "string",
"description": "id of hospital that this KPI describes"
},
"goal": {
"type": "number",
"description": "full month goal"
},
"actual": {
"type": "number",
"description": "actual result"
},
"mtd_goal": {
"type": "number",
"description": "month to date goal, so that we can track projected fulfillment of goal."
},
"details": {
"type": "object",
"description": "Semi-structured way of describing details of calculation. Every KPI will potentialiy be described differently."
}
},
"required": [
"id",
"hospital_id",
"goal",
"actual",
"mtd_goal"
]
},
"Link": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "unique id of link"
},
"hospital_id": {
"type": "string",
"description": "id of hospital that this Link is configured for"
},
"title": {
"type": "string",
"description": "human readable title for URL"
},
"description": {
"type": "string",
"description": "Description of current link (alt text , or tooltip)"
},
"url": {
"type": "string",
"description": "Location of external resource"
},
"urgent": {
"type": "boolean",
"description": "Is urgency of notification elevated?"
},
"count": {
"type": "number",
"description": "Actual notification value. How many 'tasks' are waiting manager in external system."
},
"updated_at": {
"type": "integer",
"description": "Date/time of last notification update",
"format": "int64"
},
"children": {
"type": "array",
"description": "Since notifications are possibly presented in hierarchy all children of this notification will be gathered here",
"items": {
"$ref": "#/components/schemas/Link"
}
}
},
"required": [
"id",
"hospital_id",
"title",
"url"
],
"example": [
{
"id": 1,
"hospital_id": "001",
"title": "Link1",
"description": "description of Link1",
"url": "https://www.example.com/link1",
"urgent": true,
"count": 1,
"updated_at": 1631113184221,
"children": [
{
"id": 2,
"hospital_id": "001",
"title": "Link2",
"description": "description of Link2",
"url": "https://www.example.com/link2",
"urgent": true,
"count": 1,
"updated_at": 1631113184221
}
]
},
{
"id": 3,
"hospital_id": "002",
"title": "Link3",
"description": "description of Link3",
"url": "https://www.example.com/link3",
"urgent": false,
"count": 2,
"updated_at": 1631113184221
}
]
}
}
}
}

400 Bad Request on Alexa AddOrUpdateReport using JSON from documentation

My issue is basically described in title but I'll add a little bit more details here.
I'm trying to proactively send an update report to Alexa's Event Hub for Smart Home skills, however this fails with a 400 Bad Request error, and this is what the server responds:
{
"header": {
"namespace": "System",
"name": "Exception",
"messageId": "a154410c-2364-4c5b-9028-accde5048e1e"
},
"payload": {
"code": "INVALID_REQUEST_EXCEPTION",
"description": "Event or endpoint is missing in the request."
}
}
I decided then to check if my request was wrong by sending the one that can be found on their documentation, and I'm getting the very same error.
This is the JSON copied from Amazon's documentation (I just replaced device metadata and the token):
{
"event": {
"header": {
"namespace": "Alexa.Discovery",
"name": "AddOrUpdateReport",
"payloadVersion": "3",
"messageId": "5f8a426e-01e4-4cc9-8b79-65f8bd0fd8a4"
},
"payload": {
"endpoints": [
{
"endpointId": "<unique ID of the endpoint>",
"manufacturerName": "Sample Manufacturer",
"description": "Smart Light by Sample Manufacturer",
"friendlyName": "Kitchen Light",
"additionalAttributes": {
"manufacturer" : "Sample Manufacturer",
"model" : "Sample Model",
"serialNumber": "<the serial number of the device>",
"firmwareVersion" : "<the firmware version of the device>",
"softwareVersion": "<the software version of the device>",
"customIdentifier": "<your custom identifier for the device>"
},
"displayCategories": [
"LIGHT"
],
"capabilities": [
{
"type": "AlexaInterface",
"interface": "Alexa.PowerController",
"version": "3",
"properties": {
"supported": [
{
"name": "powerState"
}
],
"proactivelyReported": true,
"retrievable": true
}
},
{
"type": "AlexaInterface",
"interface": "Alexa.BrightnessController",
"version": "3",
"properties": {
"supported": [
{
"name": "brightness"
}
],
"proactivelyReported": true,
"retrievable": true
}
}
],
"connections": [
],
"cookie": {
}
}
],
"scope": {
"type": "BearerToken",
"token": "access-token-from-Amazon"
}
}
}
}
What I don't understand is why it reports that event or endpoints are missing if they're clearly there and if this JSON is the one that they provide in their documentation.
Does anyone have this issue too?
EDIT: pasting my payload as requested.
{
"event": {
"header": {
"namespace": "Alexa.Discovery",
"name": "AddOrUpdateReport",
"payloadVersion": "3",
"messageId": "132137185729061389"
},
"payload": {
"endpoints": [
{
"endpointId": "Rmxvb2RTZW5zb3JfMDE=",
"friendlyName": "Flood sensor",
"description": "Flood sensor",
"manufacturerName": "MyCompany",
"displayCategories": [
"ACTIVITY_TRIGGER"
],
"cookie": {
"DeviceType": "FloodSensor"
},
"capabilities": [{
"interface": "Alexa",
"type": "AlexaInterface",
"version": "3"
},
{
"interface": "Alexa.EndpointHealth",
"type": "AlexaInterface",
"version": "3",
"properties": {
"supported": [{
"name": "connectivity"
}],
"proactivelyReported": true,
"retrievable": true
}
}
]
}
],
"scope": {
"type": "BearerToken",
"token": "<redacted>"
}
}
}
}

Alexa Skill Not Calling Endpoint Under Certain Conditions

I am developing an Alexa skill and testing it in the Alexa Developer Console. I am having issues with certain questions I ask will trigger no response. On these occasions, my endpoint is not getting called, or the DefaultFallback intent being fired.
I can re-produce the error and it only happens on certain questions. The debug log shows the entries below. I have deployed the skill to a device and get the same response (i.e. nothing). The skill remains open as I can continue to ask other questions and get a response.
If I substitute the word 'sausage' for certain words it gives no response, but using a word such as 'free' will return a response.
Run out of ideas about what is going on...
Event: Text.TextMessage
{
"event": {
"header": {
"namespace": "Text",
"name": "TextMessage",
"messageId": "messageId",
"dialogRequestId": "ba1efffc-b29e-4cef-bcc0-3ceb418b89ec"
},
"payload": {
"textMessage": "do you have any sausage samples"
}
},
"context": [
{
"header": {
"namespace": "System",
"name": "SettingsState",
"payloadVersion": "1"
},
"payload": {
"settings": [
{
"key": "com.amazon.alexa.characteristics.viewport.experiences",
"value": "[{\"arcMinuteWidth\":\"246\",\"arcMinuteHeight\":\"144\",\"canRotate\":\"false\",\"canResize\":\"false\"}]"
},
{
"key": "com.amazon.alexa.characteristics.viewport.shape",
"value": "RECTANGLE"
},
{
"key": "com.amazon.alexa.characteristics.viewport.pixelWidth",
"value": "1024"
},
{
"key": "com.amazon.alexa.characteristics.viewport.pixelHeight",
"value": "600"
},
{
"key": "com.amazon.alexa.characteristics.viewport.dpi",
"value": "160"
},
{
"key": "com.amazon.alexa.characteristics.viewport.currentPixelWidth",
"value": "1024"
},
{
"key": "com.amazon.alexa.characteristics.viewport.currentPixelHeight",
"value": "600"
},
{
"key": "com.amazon.alexa.characteristics.viewport.touch",
"value": "[\"SINGLE\"]"
}
]
}
},
{
"header": {
"namespace": "SpeechSynthesizer",
"name": "SpeechState"
},
"payload": {
"token": "amzn1.as-ct.v1.ThirdPartySdkSpeechlet#ACRI#ValidatedSpeakDirective_amzn1.ask.skill.8f0abe6c-a5e8-4585-912f-4e21df999811_6bf05e00-bc3a-4b1e-8b40-9664b36c0378",
"offsetInMilliseconds": 1000,
"playerActivity": "FINISHED"
}
},
{
"header": {
"namespace": "AudioPlayer",
"name": "PlaybackState"
},
"payload": {
"token": "",
"offsetInMilliseconds": 0,
"playerActivity": "IDLE"
}
},
{
"header": {
"namespace": "Alerts",
"name": "AlertsState"
},
"payload": {
"activeAlerts": [],
"allAlerts": []
}
},
{
"header": {
"namespace": "VisualFocusManager",
"name": "VisualFocusState"
},
"payload": {
"inFocus": {
"component": "ListRenderer",
"idleTimeInMilliseconds": 0
}
}
},
{
"header": {
"namespace": "AudioFocusManager",
"name": "AudioFocusState"
},
"payload": {
"dialog": {
"component": "SpeechSynthesizer",
"idleTimeInMilliseconds": 0
}
}
},
{
"header": {
"namespace": "ListRenderer",
"name": "RenderedListState"
},
"payload": {
"listToken": "amzn1.as-lt.v1.ThirdPartySdkSpeechlet#LRID#amzn1.ask.skill.8f0abe6c-a5e8-4585-912f-4e21df999811::JTEXd",
"itemsVisibleOnScreen": [],
"selectedItems": [],
"focusedItem": {},
"renderedItemDetail": {
"listItemIdentifier": "amzn1.as-lt.v1.ThirdPartySdkSpeechlet#LRID#amzn1.ask.skill.8f0abe6c-a5e8-4585-912f-4e21df999811::JTEXd",
"ordinalNumber": 1
},
"highestOrdinalSeen": 1,
"lastItemOrdinal": 1
}
}
]
}
Directive: SpeechRecognizer.RequestProcessingCompleted
{
"header": {
"namespace": "SpeechRecognizer",
"name": "RequestProcessingCompleted",
"messageId": "77057f6b-8f91-4fb4-aab0-c86efc934adc",
"dialogRequestId": "ba1efffc-b29e-4cef-bcc0-3ceb418b89ec"
},
"payload": {}
}
Directive: SkillDebugger.CaptureDebuggingInfo
{
"header": {
"namespace": "SkillDebugger",
"name": "CaptureDebuggingInfo",
"messageId": "c3175e0f-3c0a-450c-8ef4-5246ce2e1a31"
},
"payload": {
"skillId": null,
"timestamp": "2019-01-21T10:25:31.211Z",
"dialogRequestId": "ba1efffc-b29e-4cef-bcc0-3ceb418b89ec",
"skillRequestId": null,
"type": "ConsideredIntents",
"content": {
"intents": [
{
"name": "General_MobileApp",
"confirmationStatus": "NONE",
"slots": {
"Deliverables": {
"name": "Deliverables",
"value": "samples",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.8f0abe6c-a5e8-4585-912f-4e21df999811.MARSHALLS_Deliverables",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "samples",
"id": "6ef9161b900632671022358216c7dfe7"
}
}
]
}
]
},
"confirmationStatus": "NONE"
},
"Company": {
"name": "Company",
"value": "you",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.8f0abe6c-a5e8-4585-912f-4e21df999811.MARSHALLS_Company",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "Marshalls",
"id": "abfd923a6acfc93e81ba94b0310b47b2"
}
}
]
}
]
},
"confirmationStatus": "NONE"
},
"Media": {
"name": "Media",
"value": null,
"confirmationStatus": "NONE"
},
"Contact": {
"name": "Contact",
"value": null,
"confirmationStatus": "NONE"
}
}
}
]
}
}
}
Edit:
I now think a certain confidence score is not being met causing the intent not to fire (but not then calling the default fallback intent). If I ask 'flag laying patterns' the intent fires correctly and I get a full debug trace:-
If I ask 'flag laying sausages' then I get a small debug trace together with the same considered intent, but no answer and no endpoint call:-

Custom intent handler is not triggering and instead an alexa default intent is being called

so I have written a handler for an intent where the user asks Alexa to recommend a service i.e. "Alexa could you recommend a plumber". The problem is that Alexa comes in an triggers its default recommendation action.
The conversation is as follows:
User: Alexa open Bucharest insight
Alexa: Hi, welcome to Bucharest Insight, how are you? you can ask me questions about the local news or ask me for a recommendation.
User: I need a plumber
Alexa: Here are a few top-rated ones
I was expecting my getRecommendationIntentHandler to be triggered as I have setup the intent correctly ( See the below JSON) - "I need a {serviceName}",
The result from Alexa seems like a build in response instead of my custom intent handler below:
const getRecommendationIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'getRecommendationIntent';
},
handle(handlerInput) {
console.log('Called getRecommendationIntentHandler');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
// Get the filled slots inputted by the user
const slotValues = getSlotValues(filledSlots);
console.log(JSON.stringify(slotValues));
const speechText = 'getRecommendationIntentHandler called';
return responseBuilder
.speak(speechText)
.getResponse();
},
};
I have attached my JSON from Alexa Skills Kit below)
{
"interactionModel": {
"languageModel": {
"invocationName": "bucharest insight",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "NewsIntent",
"slots": [],
"samples": [
"What's the latest news",
"Tell me the news",
"Can you tell me the news please",
"I want the news",
"Play the news"
]
},
{
"name": "getRecommendationIntent",
"slots": [
{
"name": "serviceName",
"type": "AMAZON.ProfessionalType",
"samples": [
"Do you have {serviceName}",
"I would like to get a {serviceName}",
"An {serviceName}",
"A {serviceName}",
"{serviceName}",
"I would like a {serviceName}"
]
}
],
"samples": [
"Have you got any plumbers",
"Do you know a good {serviceName}",
"Do you know of a good {serviceName}",
"Can you recommend me a {serviceName} please",
"I want a {serviceName} do you know anyone",
"Have you got any good {serviceName}",
"Can you find me a {serviceName}",
"I need a {serviceName}",
"Can you find me a good {serviceName}",
"Do you know of any good {serviceName}",
"Can you recommend me a {serviceName}"
]
},
{
"name": "AMAZON.PauseIntent",
"samples": []
},
{
"name": "AMAZON.ResumeIntent",
"samples": []
}
],
"types": [
{
"name": "AMAZON.ProfessionalType",
"values": [
{
"name": {
"value": "fashion designer",
"synonyms": [
"Fashion",
"clothes designer"
]
}
},
{
"name": {
"value": "Interior designer",
"synonyms": [
"Home designer"
]
}
},
{
"name": {
"value": "Painter",
"synonyms": [
"Painting"
]
}
},
{
"name": {
"value": "Electrician",
"synonyms": [
"Electric man"
]
}
},
{
"name": {
"value": "Plumber",
"synonyms": [
"plumber",
"Water man"
]
}
}
]
}
]
},
"dialog": {
"intents": [
{
"name": "getRecommendationIntent",
"confirmationRequired": true,
"prompts": {
"confirmation": "Confirm.Intent.508140955512"
},
"slots": [
{
"name": "serviceName",
"type": "AMAZON.ProfessionalType",
"confirmationRequired": true,
"elicitationRequired": true,
"prompts": {
"confirmation": "Confirm.Slot.508140955512.325067758753",
"elicitation": "Elicit.Slot.508140955512.325067758753"
}
}
]
}
]
},
"prompts": [
{
"id": "Elicit.Slot.508140955512.325067758753",
"variations": [
{
"type": "PlainText",
"value": "What service do you want?"
},
{
"type": "PlainText",
"value": "Can you tell me what you're looking for ?"
},
{
"type": "PlainText",
"value": "What's the serivice you are looking for?"
}
]
},
{
"id": "Confirm.Slot.508140955512.325067758753",
"variations": [
{
"type": "PlainText",
"value": "So you want to find a {serviceName} , correct?"
}
]
},
{
"id": "Confirm.Intent.508140955512",
"variations": [
{
"type": "PlainText",
"value": "So you want me to find a {serviceName} , is that correct?"
},
{
"type": "PlainText",
"value": "So you want me to recommend you a {serviceName} , am I right ?"
}
]
}
]
}
}
Any help would be much appreciated and I am open to further questions about this.
-- New comment 06/09/2018 - This is the JSON created by Alexa:
JSON Input:
{
"version": "1.0",
"session": {
"new": true,
"sessionId": "amzn1.echo-api.session.5688bb9b-0f5c-4616-9c8d-46d2218a167b",
"application": {
"applicationId": "amzn1.ask.skill.180e6d66-06c5-412c-8fe0-90f2fcc31a3a"
},
"user": {
"userId": "amzn1.ask.account.AEHB6UB7SDQU6TCKZOEADQ2ICGLSXETSXC6LOJSRXWAPGWLBBXQIKKH2GTFRLO6NIKLCXIRJBQLXAT45OCKP4UHMPSCM33M5ZE4M4EE5MARUBLF7BNTL6WWAIWKOL3WMYCWT7SCOKQHROFD3VEJTPN3JFCLWQ46ZRY6UGSENVLPFIHPQGQZNV3T6UQ4TEXGFNMHX6PCLTHZUS5I"
}
},
"context": {
"AudioPlayer": {
"playerActivity": "IDLE"
},
"System": {
"application": {
"applicationId": "amzn1.ask.skill.180e6d66-06c5-412c-8fe0-90f2fcc31a3a"
},
"user": {
"userId": "amzn1.ask.account.AEHB6UB7SDQU6TCKZOEADQ2ICGLSXETSXC6LOJSRXWAPGWLBBXQIKKH2GTFRLO6NIKLCXIRJBQLXAT45OCKP4UHMPSCM33M5ZE4M4EE5MARUBLF7BNTL6WWAIWKOL3WMYCWT7SCOKQHROFD3VEJTPN3JFCLWQ46ZRY6UGSENVLPFIHPQGQZNV3T6UQ4TEXGFNMHX6PCLTHZUS5I"
},
"device": {
"deviceId": "amzn1.ask.device.AFYZEJWCDICBPMGAGXM2TNFW4MMZCWWGVFATSXL6ARKMXBENBTS5U2M2PAQJRTBQB2OR2X5HHCM4A7CWIWNOCFIP4LF2LXH6F5OND5425SXYUONA6NTJ67LM2Z27OOAAJ4WXW4COPWZXNP7KMK2YIHDOMUSQ",
"supportedInterfaces": {
"AudioPlayer": {}
}
},
"apiEndpoint": "https://api.eu.amazonalexa.com",
"apiAccessToken": "Redacted by me"
}
},
"request": {
"type": "LaunchRequest",
"requestId": "amzn1.echo-api.request.c17bb90f-8c8d-4b4c-ab1f-0462ab5f2c05",
"timestamp": "2018-09-06T06:29:14Z",
"locale": "en-US",
"shouldLinkResultBeReturned": false
}
}
JSON Output
{
"body": {
"version": "1.0",
"response": {
"outputSpeech": {
"type": "SSML",
"ssml": "<speak>Hi, welcome to Bucharest Insight, how are you ? you can ask me questions about the local news or ask me for a recommendation</speak>"
}
},
"sessionAttributes": {},
"userAgent": "ask-node/2.0.5 Node/v8.10.0"
}
}
Event.TextMessage
{
"event": {
"header": {
"namespace": "Text",
"name": "TextMessage",
"messageId": "messageId",
"dialogRequestId": "6ecb05d5-905f-4c9f-aae0-bbeb028062db"
},
"payload": {
"textMessage": "i need a plumber"
}
},
"context": [
{
"header": {
"namespace": "SpeechSynthesizer",
"name": "SpeechState"
},
"payload": {
"token": "amzn1.as-ct.v1.ThirdPartySdkSpeechlet#ACRI#ValidatedSpeakDirective_amzn1.ask.skill.180e6d66-06c5-412c-8fe0-90f2fcc31a3a_0b040a2a-a5bc-4d43-9452-95c49c3cca1c",
"offsetInMilliseconds": 1000,
"playerActivity": "FINISHED"
}
},
{
"header": {
"namespace": "AudioPlayer",
"name": "PlaybackState"
},
"payload": {
"token": "",
"offsetInMilliseconds": 0,
"playerActivity": "IDLE"
}
},
{
"header": {
"namespace": "Alerts",
"name": "AlertsState"
},
"payload": {
"activeAlerts": [],
"allAlerts": []
}
},
{
"header": {
"namespace": "VisualFocusManager",
"name": "VisualFocusState"
},
"payload": {
"inFocus": {
"component": "ListRenderer",
"idleTimeInMilliseconds": 0
}
}
},
{
"header": {
"namespace": "AudioFocusManager",
"name": "AudioFocusState"
},
"payload": {
"alert": {
"component": null,
"idleTimeInMilliseconds": 0
},
"dialog": {
"component": "SpeechSynthesizer",
"idleTimeInMilliseconds": 1000
},
"content": {
"component": null,
"idleTimeInMilliseconds": 0
}
}
},
{
"header": {
"namespace": "ListRenderer",
"name": "RenderedListState"
},
"payload": {
"listToken": "amzn1.as-lt.v1.ThirdPartySdkSpeechlet#LRID#amzn1.ask.skill.180e6d66-06c5-412c-8fe0-90f2fcc31a3a::Latuc",
"itemsVisibleOnScreen": [],
"selectedItems": [],
"focusedItem": {},
"renderedItemDetail": {
"listItemIdentifier": "amzn1.as-lt.v1.ThirdPartySdkSpeechlet#LRID#amzn1.ask.skill.180e6d66-06c5-412c-8fe0-90f2fcc31a3a::Latuc",
"ordinalNumber": 1
},
"highestOrdinalSeen": 1,
"lastItemOrdinal": 1
}
}
]
}
Directive: SpeechSynthesizer.Speak
{
"header": {
"namespace": "SpeechSynthesizer",
"name": "Speak",
"messageId": "aa79a5f3-9293-4f49-9fda-22abeaedbe03",
"dialogRequestId": "6ecb05d5-905f-4c9f-aae0-bbeb028062db"
},
"payload": {
"caption": "Here are a few top-rated ones",
"url": "https://kopytko-eu-west-1.amazon.com/3/72c80478-b19e-11e8-aeb5-15393a31d62e-9eedcf/5/1536301872334/10f6885702786ce70473a6560e8b09fdc9a5d548d7c5f6072eaf3a18c498fce1/resource.mp3",
"format": "AUDIO_MPEG",
"token": "amzn1.as-ct.v1.DOMAIN:POI#ACRI#DeeAppPOISpeechlet",
"ssml": "<speak><prosody volume=\"x-loud\">Here are a few top-rated ones</prosody><metadata><promptMetadata><promptId>POICategory#Knight#MultipleResults</promptId><namespace>POI</namespace><locale>en_US</locale><overrideId>default</overrideId><variant>1</variant><condition/><weight>1</weight><stageVersion>Adm-20180810_234837-1</stageVersion></promptMetadata></metadata></speak>"
}
}
Directive.ListRenderer.RenderList
{
"header": {
"namespace": "ListRenderer",
"name": "RenderList",
"messageId": "d79a03bb-b1cf-4722-a24a-a982f2b89da7",
"dialogRequestId": "6ecb05d5-905f-4c9f-aae0-bbeb028062db"
},
"payload": {
"name": "renderList",
"namespace": "ListRenderer",
"listToken": "amzn1.as-lt.v1.DOMAIN:POI#LRID#a1be83a5-35d9-41c9-94c1-066e7152fc45",
"totalNumberOfItems": 4,
"listPage": {
"listItems": [
..... (Too long to display here)
Directive: ListRenderer.ReadListItems
{
"header": {
"namespace": "ListRenderer",
"name": "ReadListItems",
"messageId": "57b1df77-1175-42bd-99a1-86ded50e7525",
"dialogRequestId": "6ecb05d5-905f-4c9f-aae0-bbeb028062db"
},
"payload": {
"listToken": "amzn1.as-lt.v1.DOMAIN:POI#LRID#a1be83a5-35d9-41c9-94c1-066e7152fc45",
"beginOrdinal": 1,
"count": 4
}
}
Directive: SpeechRecognizer.RequestProcessingCompleted
{
"header": {
"namespace": "SpeechRecognizer",
"name": "RequestProcessingCompleted",
"messageId": "59a2194d-f04f-43f4-9269-8bbe0c3c3809",
"dialogRequestId": "6ecb05d5-905f-4c9f-aae0-bbeb028062db"
},
"payload": {}
}
Your first response does not have shouldEndSession parameter. If not provided, defaults to true. What that means is that, once your response is read, Alexa will end the session and closes the skill. You are no longer inside the skill. Whenever you want Alexa to wait for user response, keep the session alive by setting shouldEndSession parameter set to false.
Your first response should be like this:
{
"body": {
"version": "1.0",
"response": {
"outputSpeech": {
"type": "SSML",
"ssml": "<speak>Hi, welcome to Bucharest Insight, how are you ? you can ask me questions about the local news or ask me for a recommendation</speak>"
},
"shouldEndSession": false
},
"sessionAttributes": {},
"userAgent": "ask-node/2.0.5 Node/v8.10.0"
}
}
The good thing is that, you don't have to set this parameter manually and the SDK will take care of it. For that use a reprompt. Including a reprompt in your response is a good design.
return responseBuilder
.speak(speechText)
.reprompt(repromptSpeechOutput)
.getResponse();
If you don't want to use a reprompt you can use withShouldEndSession(false).
Read this answer for more.

Send workflow information to custom connector

I need help with sending workflow information in header/body of calls to custom connector. I am trying to load a drop down list in one of the parameters of a logic app using values returned from an API call. The API end point requires basic workflow information such as the resource group and workflow name which are normally available in headers of http requests from logic app execution.
Normally when I use #{workflow().name} in logic app's json, it is substituted with the workflow name. In case of custom connector, the WDL syntax is passed as is without any transformation.
Here is a simplified swagger json with all relevant sections.
{
"swagger": "2.0",
"info": {
"title": "{{dynamicHostName}}",
"version": "1.0.0"
},
"host": "{{dynamicHostName}}",
"basePath": "/",
"schemes": [
"https"
],
"paths": {
"/sftpsource": {
"post": {
"operationId": "SftpSource",
"summary": "Sftp as source system",
"description": "Use Sftp as source system",
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"parameters": [
{
"name": "params",
"in": "body",
"required": true,
"schema": {
"type": "object",
"properties": {
"hostName": {
"type": "string",
"x-ms-summary": "Host Name",
"x-ms-visibility": "advanced"
},
"portNumber": {
"type": "string",
"x-ms-summary": "Port Number",
"x-ms-visibility": "advanced"
},
"userName": {
"type": "string",
"x-ms-summary": "User Name",
"x-ms-visibility": "advanced"
},
"password": {
"type": "string",
"x-ms-summary": "Password",
"x-ms-visibility": "advanced"
},
"filePath": {
"type": "string",
"x-ms-summary": "File Path"
},
"system": {
"type": "string",
"x-ms-visibility": "advanced",
"x-ms-summary": "System",
"x-ms-dynamic-values": {
"operationId": "GetTaggedSystems",
"parameters": {
"workflow-name": "#{workflow().name}"
},
"value-path": "systemId",
"value-title": "systemName"
}
}
}
}
}
],
"responses": {
"202": {
"description": "Request is queued"
},
"500": {
"description": "Server Error"
}
}
}
},
"/taggedSystems" : {
"get": {
"operationId": "GetTaggedSystems",
"summary": "Tagged Systems",
"x-ms-visibility": "advanced",
"description": "Get all systems tagged to this flow",
"parameters": [
{
"name": "workflow-name",
"in": "header",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/TaggedSystems"
}
},
"202": {
"description": "Work is still in progress"
},
"500": {
"description": "An error occured while trying to fetch tagged systems."
}
}
}
}
},
"definitions": {
"TaggedSystems": {
"type": "array",
"items": {
"type": "object",
"properties": {
"systemId": {
"type": "string"
},
"systemName": {
"type": "string"
}
},
"required": [
"systemId",
"systemName"
]
}
}
}
}
You can have an internal parameter defined as header/body where you can pass dynamic expressions of what you need from the workflow environment at the time of execution of the flow.
For complete information regarding the flow, you can pass #{workflow()} as an internal parameter.
Hope it helps.

Resources