Chatbase send multiple messages at once error sequence - chatbase

I'm using https://chatbase.com/api/messages Chatbase API to send multiple messages to the Chatbase. The documentation stats that the response would provide error and success for individual messages that are sent in the request.
How I should detect which message is failed out of the 3 messages that I have provided in the request if the response provides error for one message?
JSON Request body for sending multiple messages
{
"messages": [
{
"api_key": "<API KEY>",
"type": "agent",
"user_id": "User_1",
"time_stamp": 1542895834,
"platform": "XXX",
"message": "Test 1",
"not_handled": false,
"version": "1.0",
"session_id": "session-User_1"
},
{
"api_key": "<API KEY>",
"type": "agent",
"user_id": "User_1",
"time_stamp": 1542895834,
"platform": "XXX",
"message": "Test 2",
"not_handled": false,
"version": "1.0",
"session_id": "session-User_1"
},
{
"api_key": "<API KEY>",
"type": "agent",
"user_id": "User_1",
"time_stamp": 1542895834,
"platform": "XXX",
"message": "Test 3",
"not_handled": false,
"version": "1.0",
"session_id": "session-User_1"
}
]
}
JSON Response body
{
"all_succeeded": false,
"responses": [
{
"error": "Error fetching parameter 'type': Invalid conversation type [dfg]",
"status": "error"
},
{
"message_id": 139429278,
"status": "success"
},
{
"error": "Error fetching parameter 'time_stamp': Received a time (1921-02-09 09:49:26) which was too small. Please send a time within the past day for metrics to appear in the dashboards, or omit the time_stamp field for the time to automatically be set to now.",
"status": "error"
}
],
"status": 200
}

The order of the error messages will correspond to the order of the messages you submitted. In this case, it was the first and third messages. I also noticed that you are not using unix milliseconds in your timestamps. The messages will need to be at least one millisecond apart in order to sort them correctly in the Chatbase reports.

Related

How to send to Amazon's Alexa Event Gateway?

I am trying to test sending an event to the Amazon's Event Gateway for my Alexa Smart Home skill using Postman but I keep receiving an 'invalid access token exception.' I have read the Amazon's documentation on this but apparently I am missing something.
When I enable my skill, my Smart Home Lambda receives the AcceptGrant.
{
"directive": {
"header": {
"namespace": "Alexa.Authorization",
"name": "AcceptGrant",
"messageId": "b2862179-bc56-4bb2-ac05-ce55c7a3e977",
"payloadVersion": "3"
},
"payload": {
"grant": {
"type": "OAuth2.AuthorizationCode",
"code": "ANSVjPzpTDBsdfoRSyrs"
},
"grantee": {
"type": "BearerToken",
"token": "Atza|IwEB..."
}
}
}
}
My lambda sends a POST to 'https://api.amazon.com/auth/o2/token' to receive the Access and Refresh tokens. It then stores those tokens. Next, my Lamdba responds with the following:
{
"event": {
"header": {
"namespace": "Alexa.Authorization",
"name": "AcceptGrant.Response",
"messageId": "b2862179-bc56-4bb2-ac05-ce55c7a3e977",
"payloadVersion": "3"
},
"payload": {}
}
}
I then get a message web page that I have successfully linked my skill - all is good.
Next, I try to send an event to Amazon's Alexa event gateway using the Postman app. I put the Access token (I also tried the Refresh token) in the header as a 'BearerToken' type and the in the 'scope' of the 'endpoint' object.
POST https://api.amazonalexa.com/v3/events?Content-Type=application/json&charset=UTF-8
with a header that specifies a Bearer Token (Access token received earlier) and a body that contains the following:
{
"event": {
"header": {
"messageId": "abc-123-def-456",
"namespace": "Alexa",
"name": "ChangeReport",
"payloadVersion": "3"
},
"endpoint": {
"scope": {
"type": "BearerToken",
"token": "<access token>"
},
"endpointId": "MySmartSwitch-001"
},
"payload": {
"change": {
"cause": {
"type": "RULE_TRIGGER"
},
"properties": [
{
"namespace": "Alexa.ModeController",
"name": "mode",
"value": "Backup",
"timeOfSample": "2020-01-02T09:30:00ZZ",
"uncertaintyInMilliseconds": 50
}
]
}
}
},
"context": {
"properties": [
{
"namespace": "Alexa.PowerController",
"name": "powerState",
"value": "ON",
"timeOfSample": "2020-01-02T09:30:00Z",
"uncertaintyInMilliseconds": 60000
},
{
"namespace": "Alexa.EndpointHealth",
"name": "connectivity",
"value": {
"value": "OK"
},
"timeOfSample": "2020-01-02T09:30:00Z",
"uncertaintyInMilliseconds": 0
}
]
}
}
The response received is '401 Unauthorized'
{
"header": {
"namespace": "System",
"name": "Exception",
"messageId": "95bd23c3-76e6-472b-9c6d-74d436e1eb61"
},
"payload": {
"code": "INVALID_ACCESS_TOKEN_EXCEPTION",
"description": "Access token is not valid."
}
}
I figured out the issue. I was mistakenly sending parameters: Content-Type=application/json and charset=UTF-8 as well including them in the header - my bad. You just need to include them in the header.

POST JSON to log event into Application Insights

I need to write a PowerShell Script shell to log an entry into App Insights. I found this post which is useful but I am having a hard time writing to different fields other than the ones being used there. For example I am trying to populate the message field. I don't know the field name in JSON and I don't know where it should go. As you can see in this example I tried placing it everywhere and still did not work. I tried searching for their REST API documentation and still can't find the specs for the JSON.
Can anyone help?
[{
"name": "Microsoft.ApplicationInsights.Event",
"time": "2018-09-20T16:57:16.1771869Z",
"iKey": "1234",
"message": "This is a message",
"tags": {
"ai.operation.name": "Name",
"ai.user.id": "userId",
"ai.cloud.roleInstance": "Machine 1"
},
"data": {
"baseType": "EventData",
"message": "message1",
"baseData": {
"name": "Event from my service",
"message": "message2",
"properties": {
"x": "value x",
"y": "value y",
"z": "value z"
}
}
}
}]
We've been recently trying to achieve the same and didn't find good instructions on the web too, so posting our findings here.
1. API Endpoint
1.1 Authentication
You will need your instrumentation key - see How to get Azure Instrumentation Key for details. That key must be stored in the "iKey" property of the message payload.
1.2 Request
Overall, there seem to be 4 different message types (defined by the "baseType" property) that can be set. All of them need to are sent via POST to the same endpoint
POST https://dc.services.visualstudio.com/v2/track
[ { MESSAGE1 }, { MESSAGE2 }, ... ]
Where the format of each message depends on its type. No authentication headers are needed - the "iKey" field of the message serves as the authentication key.
1.3 Response
The following response is sent in case of success
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"itemsReceived" : 1,
"itemsAccepted" : 1,
"errors":[]
}
Where the "itemsAccepted" property will indicate the number of records accepted by Application Insights.
2. Message Formats
Each individual message in the array must follow one of the following 4 possible JSON formats.
2.1 The "EventData" ("CUSTOM EVENT") message format
This event is shown as the "Custom Event" in the Application Insights. The following payload must be used:
{
"name": "Microsoft.ApplicationInsights.Event",
"time": "2015-05-21T16:43:14.4670675-06:00",
"iKey": "[MyInstrumentationKey]",
"tags": {
},
"data": {
"baseType": "EventData",
"baseData": {
"ver": 2,
"name": "SampleEvent",
"properties": {
"x": "value x",
"y": "value y",
"z": "value z"
}
}
}
}
2.2 The "MessageData" ("TRACE") message format
This event is shown as the "TRACE" in the Application Insights. The following payload must be used:
{
"name": "Microsoft.ApplicationInsights.Event",
"time": "2021-02-25T21:35:45.0000000Z",
"iKey": "[MyInstrumentationKey]",
"tags":{
},
"data": {
"baseType": "MessageData",
"baseData": {
"ver": 2,
"message": "Simple Trace Log Message",
"severityLevel": 2,
"properties": {
"x": "value x",
"y": "value y",
"z": "value z"
}
}
}
}
severityLevel meaning
level 0 = "Verbose"
level 1 = "Information"
level 2 = "Warning"
level 3 = "Error"
level 4 = "Critical"
2.3 The "MetricData" message format
The following payload must be used:
{
"name": "Microsoft.ApplicationInsights.Event",
"time": "2021-02-25T21:35:45.0000000Z",
"iKey": "[MyInstrumentationKey]",
"tags": {
},
"data": {
"baseType": "MetricData",
"baseData": {
"ver": 2,
"metrics": [
{
"name": "BasicMetric",
"kind": "Measurement",
"value": 42
}
],
"properties": {
"x": "value x",
"y": "value y",
"z": "value z"
}
}
}
}
2.4 The "ExceptionData" message format
The following payload must be used:
{
"name": "Microsoft.ApplicationInsights.Event",
"time": "2021-02-25T21:35:45.0000000Z",
"iKey": "[MyInstrumentationKey]",
"tags": {
},
"data": {
"baseType": "ExceptionData",
"baseData": {
"ver": 2,
"handledAt": "UserCode",
"properties": {
"x": "value x",
"y": "value y",
"z": "value z"
},
"exceptions": [
{
"id": 26756241,
"typeName": "System.Exception",
"message": "Something bad has happened!",
"hasFullStack": true,
"parsedStack": [
{
"level": 0,
"method": "Console.Program.Main",
"assembly": "Console, Version=1.0",
"fileName": "/ApplicationInsights/Test.cs",
"line": 42
}
]
}
]
}
}
}
You can put the message in the properties:{}.
After execute the powershell script, go to azure portal, you should see the message field there:
But if you wanna add a field in the Custom Event Properties section, there seams no way to do it.

Dialogflow - Fulfillment Webhook Response different from Documentation

I'm currently using Dialogflow in combination with fulfillment/webhooks.
In the documentation of the fulfillments there is an example POST request for webhooks:
POST body:
{
"contexts": [
string
],
"lang": string,
"query": string,
"sessionId": string,
"timezone": string
}
The request that I'm receiving on my end is different from what is defined in the documentation. Has somebody an idea why?
This is what I receive:
{
"id": "GUID",
"timestamp": "2018-01-12T12:25:32.202Z",
"lang": "de",
"result": {
"source": "agent",
"resolvedQuery": "Test",
"speech": "",
"action": "",
"actionIncomplete": false,
"parameters": {
"Nummer": ""
},
"contexts": [],
"metadata": {
"intentId": "XYZ",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"intentName": "Intent"
},
"fulfillment": {
"speech": "",
"messages": [{
"type": 0,
"speech": ""
}]
},
"score": 0.6700000166893005
},
"status": {
"code": 200,
"errorType": "success",
"webhookTimedOut": false
},
"sessionId": "GUID"
}
I've found that different invocation sources send slightly different data to the web hook.
For example the Google Action simulator will send different information in the context reply than say the test pane in an intent.
Im guessing that the answer may lie in where/how your calling the web hook.

Status 206 from api.ai https webhook

I currently have a working ExpressJS webhook for api.ai hosted on EC2.
However, my backend fails when I use the identical GET/POST handlers in an https webhook. In particular, I don't see any (console.log) output from the POST handler, and my api.ai action returns a 206 error.
I've verified that the https webhook server is reachable from a browser. TIA for any suggestions
The api.ai JSON status is below:
{
"id": "ff86f1da-a136-4ec2-b7f8-4aa7cb443f5a",
"timestamp": "2017-07-16T19:04:27.522Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "add bread",
"action": "",
"actionIncomplete": false,
"parameters": {
"number": "",
"shopping_item": "bread",
"unit-weight-name": ""
},
"contexts": [],
"metadata": {
"intentId": "7ea8b3b1-28d6-418e-b9d2-b7353bf5a008",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"webhookResponseTime": 126,
"intentName": "add shopping item"
},
"fulfillment": {
"speech": "done",
"messages": [
{
"type": 0,
"speech": "okey-dokey"
}
]
},
"score": 0.9599999785423279
},
"status": {
"code": 206,
"errorType": "partial_content",
"errorDetails": "Webhook call failed. Error: Webhook response was empty."
},
"sessionId": "963f3693-5fa3-4d45-a3f3-817f9d433965"
}
The POST handler is below.
app.post('/',function(req, res){
res.setHeader('Content-Type', 'application/json');
//debugging output for the terminal
console.log('you posted: Id: ' + req.body.id + ', Item: ' + req.body.result.parameters.shopping_item
+ ', Query: '+req.body.result.resolvedQuery);
jsonObj={};
jsonObj["displayText"]=req.body.result.parameters.shopping_item;
jsonObj["textToSpeech"]=req.body.result.parameters.shopping_item;
jsonObj["formattedText"]=req.body.result.parameters.shopping_item;
response = "added - "+req.body.result.parameters.shopping_item;
res.send(JSON.stringify({ "speech": response, "displayText": response}));
});

API.AI does not connect to my back-end

I'm writing an agent using API.AI I'm observing that my back-end is not called everytime. I can see that in my access logs. Any idea what can cause the issue?
Here is the response of the console:
{
"id": "c1902c75-1550-43f6-9cc8-b0461f1dfac7",
"timestamp": "2016-12-22T19:58:13.49Z",
"result": {
"source": "agent",
"resolvedQuery": "echo test",
"action": "",
"actionIncomplete": false,
"parameters": {
"myInput": "test"
},
"contexts": [],
"metadata": {
"intentId": "062b4383-06a0-40fe-bbeb-9189db49aeb8",
"webhookUsed": false,
"webhookForSlotFillingUsed": "false",
"intentName": "Response"
},
"fulfillment": {
"speech": "",
"messages": [
{
"type": 0,
"speech": ""
}
]
},
"score": 0.75
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "70be8f65-81f0-40be-a271-84a2d4960224"
}
I see there no error which explains why my backend is not called.
Here is a screenshot of my intent:
You have not given any value in the action key of the intent.Give some action name and keep this same name of your function which will accept the parameters from the api.ai
basically the flow is
1)user enters an input.
2)api.ai tries to match the user's input with the intents defined by you, if not found it will got to the fallback intent.
3)once the proper intent is matched then api.ai tries to extract the parameters from the user's sentence.
4)once all the required parameters are found it will call the action which you have defined in the intent.
NOTE: if none of the parameters are required in the intent it directly calls the action .

Resources