AWS Lex Python Codehook references - amazon-lex

I am still pretty new to Python (and coding) but I am trying to build my own Lex bot with a Lambda function. I have been following the tutorials and I can understand how it all works. Problem is when I am trying to write my own Lambda functions for Lex, I cannot find any references to help me write my code for example looking at the code below.
def get_slots(intent_request):
return intent_request['currentIntent']['slots']
What is "(intent_request)" and where would I find reference to this? Same for "['currentIntent'], how can I find out what it is and why it is there??
Sorry if this seems stupid to most people on here but I can't start writing code and continue to learn if I can't find any documentation to suggest what these are and why they are needed in order to write code for my own Lex bots.
Thanks in advance!!!

The intent_request is the incoming "request" or "event" from Lex to your Lambda Function. It holds all the necessary information about the user's input and your Lex bot's processing of that input (trigger certain intent, fill certain slots, confirmations, etc.)
This should be the documentation you are looking for.
Lambda Function Input Event and Response Format:
This section describes the structure of the event data that Amazon Lex provides to a Lambda function. Use this information to parse the input in your Lambda code. It also explains the format of the response that Amazon Lex expects your Lambda function to return.
And here is the Event/Request format:
{
"currentIntent": {
"name": "intent-name",
"slots": {
"slot name": "value",
"slot name": "value"
},
"slotDetails": {
"slot name": {
"resolutions" : [
{ "value": "resolved value" },
{ "value": "resolved value" }
],
"originalValue": "original text"
},
"slot name": {
"resolutions" : [
{ "value": "resolved value" },
{ "value": "resolved value" }
],
"originalValue": "original text"
}
},
"confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)"
},
"bot": {
"name": "bot name",
"alias": "bot alias",
"version": "bot version"
},
"userId": "User ID specified in the POST request to Amazon Lex.",
"inputTranscript": "Text used to process the request",
"invocationSource": "FulfillmentCodeHook or DialogCodeHook",
"outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
"messageVersion": "1.0",
"sessionAttributes": {
"key": "value",
"key": "value"
},
"requestAttributes": {
"key": "value",
"key": "value"
}
}
The slots data is found inside currentIntent and that is inside of this whole intent_request object. That is why you are seeing the code: intent_request['currentIntent']['slots']
So to get session attributes you can find them here: intent_request['sessionAttributes']
Also extremely useful is the exact user input text:
intent_request['inputTranscript']

Related

Slack API - how to send multiple images so they are shown in a gallery

When I send multiple images via api using blocks like this:
{
"blocks": [
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Please enjoy this photo of a kitten"
},
"image_url": "http://placekitten.com/500/500",
"alt_text": "An incredibly cute kitten."
},
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Please enjoy this photo of a kitten"
},
"image_url": "http://placekitten.com/500/500",
"alt_text": "An incredibly cute kitten."
},
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Please enjoy this photo of a kitten"
},
"image_url": "http://placekitten.com/500/500",
"alt_text": "An incredibly cute kitten."
}
]
}
Slack shows them like a separate blocks and doesn't combine them into a gallery:
slack screenshot - API
When I upload them using Slack app in one message - it combines them into a gallery:
slack screenshot - with gallery
I've tried blocks, attachments, third-party urls, permalinks after file.upload - the result is the same, Slack doesn't combine them into gallery.
So, the question is - how do I make it that Slack shows several images in a gallery?
UPD:
Just got an answer from Slack developers support:
slack dev support answer screenshot
Unfortunately, horizontal/gallery formatting of images is not possible
using the block kit builder. However, I'm going to go ahead and pass
your email on to our product team so that they can take this into
consideration for future updates.
Based on your comment,
[...] permalinks after file.upload [...]
this related answer might help (I also added this clarification there).
When uploading files and collecting their permalinks, you must link them in the text param in the message payload (putting them in a mrkdwn block in the blocks param will not work).
In javascript, this looks like:
const result1 = await web.files.upload({...})
const result2 = await web.files.upload({...})
await web.chat.postMessage({
text: `Here are files in a gallery view <${result1.file.permalink| ><${result2.file.permalink| >`,
...
})

How to get text response in survey monkey via API

I'm currently getting responses from SurveyMonkey using the v3 APIs...
I'm using the /collectors/{id}/responses/{id}/details call and I successfully getting the resp. BUT the resp has got the IDs and not the text values e.g.
{
"id": "111788228",
"answers": [
{
"choice_id": "828117913"
}
]
}
1) Can I get SM to send me the text answer?
2) If I can't how can I get the text value using the choice_id.
Thanks in advance.
There isn't a way currently to get the Survey text directly with the responses. You'll have to fetch the survey details or the details for a specific question and match the choice ID with the text for that choice on your own.
GET /v3/surveys/<survey_id>
or
GET /v3/surveys/<survey_id>/pages/<page_id>/questions/<question_id>
You'll get a body back with the choices like this:
{
...
"answers": {
"choices": [{
"id": "12345",
"visible": true,
"is_na": false,
"text": "Apples",
"position": 1
}, ...]
},
...
}
Then you can just match the id field with the choice_id field from the response.
Now there is 'bulk' API.
Look at the 'simple' option:
GET /surveys/{id}/responses/bulk?simple=true

Google Cloud Endpoints REST Discovery Document missing format

I've upgraded to Cloud Endpoints 2.0 which no longer supports RPC. Therefore, I generated a new discovery document and used the service generator with the REST discovery doc as input in order to generate the client library for my iOS app.
Using the new REST discovery doc I am getting the following error when trying to generate the library:
~/workspace/google-api-objectivec-client-for-rest/Source/Tools/ServiceGenerator/build/Release/ServiceGenerator discovery/servUsApi-v1-rest.discovery --outputDir GTLAPI --gtlrFrameworkName GoogleAPIClientForREST
ERROR: Failure, exception: Looking at parameter 'creditKickbackKash:creditAmount', found a type/format pair of 'number/(null)', and don't how to map that to Objective-C
I was able to manually fix this by adding (in numerous places) in the discovery doc, the "format": "double" key and value for all double parameters. Notice creditAmount below is missing a format, like all other doubles.
The generated discovery doc looks like this:
"creditKickbackKash": {
"httpMethod": "PUT",
"id": "servUsApi.admin.creditKickbackKash",
"parameterOrder": [
"userId",
"creditAmount"
],
"parameters": {
"userId": {
"format": "int64",
"location": "path",
"required": true,
"type": "string"
},
"creditAmount": {
"location": "path",
"required": true,
"type": "number"
}
},
"path": "creditKickbackKash/{userId}/{creditAmount}",
"response": {
"$ref": "ResultDTO"
},
"scopes": [
"https://www.googleapis.com/auth/userinfo.email"
]
}
Is anyone else having this issue? How can I get the discovery document generation to properly format the document including double number types?
I had the same problem. I rolled back from 1.9.50 to 1.9.48 and the problem is gone.

Dart Services API: how to access the /fixes through the API service?

I am looking at:
https://github.com/dart-lang/dart-services
And am trying to adapt the example given (https://dartpad.dartlang.org/2a7fd9328e0a567ee79b) to pull back information from '/api/dartservices/v1/fixes' rather than '/api/dartservices/v1/analyze'.
Apologies, if I am missing something obvious here but changing the path in the example to:
"https://dart-services.appspot.com/api/dartservices/v1/fixes";
returns an error. Does anyone know how I can get the information from '/api/dartservices/v1/fixes rather than '/api/dartservices/v1/analyze'? Or does anyone have an example of this working?
Thanks.
Sending a POST request to https://dart-services.appspot.com/api/dartservices/v1/fixes with the data the DartPad example sends yields the error message "Missing parameter: 'offset'".
Looking at the discovery doc for the service https://dart-services.appspot.com/api/discovery/v1/apis/dartservices/v1/rest I see both analyze and fixes operations take a SourceRequest:
"SourceRequest": {
"id": "SourceRequest",
"type": "object",
"properties": {
"source": {
"type": "string",
"description": "The Dart source.",
"required": true
},
"offset": {
"type": "integer",
"description": "An optional offset into the source code.",
"format": "int32"
},
"strongMode": {
"type": "boolean",
"description": "An optional signal whether the source should be processed in strong mode"
}
}
offset is not marked as required so maybe there is a bug in the implementation of fixes wrt that parameter.
To make the DartPad example work, change:
Map m = {'source': textArea.value};
to
Map m = {'source': textArea.value, 'offset': 0};

Bluemix blockchain: How can i query out this?

I need to know how to query the following invoke(AC(123456A)or (user_type1_c19a5f0b7e) when i have init this:
{
"jsonrpc": "2.0",
"method": "deploy",
"params": {
"type": 1,
"chaincodeID": {
"path": "https://github.com/johndoe/learn-chaincode/finished"
},
"ctorMsg": {
"function": "init",
"args": [
"hi there"
]
},
"secureContext": "user_type1_191b8c2993"
},
"id": 1
}
Here is my (successful) invoke:
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID": {
"name": "b42b506c13fg1157520d585841a691f4b598d9aac53adc95277ed710c7f1f5aaa59a89a8dca8ddf3e46d5241562f3316956a04ad8a33181d30cb01b1c4c9adb2f"
},
"ctorMsg": {
"function": "AC(123456A)",
"args": [
"AcctId:949392949233 ","Year2015 Sem1 ", "IT1234:A ", " IT2345:B+ ", "IT3456:A ", "Year 2015 Sem2 ", "IT4567:B ", "IT5678: B", "IT5678:A ","Year 2016 Sem1 ", "IT6789:C ", "IT7890:C ", "Cumulative GPA: 3"
]
},
"secureContext": "user_type1_c19a5f0b7e"
},
"id": 4
}
Here is the query that I am trying and I can't get the results that I want:
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID": {
"name": "b42b506c13fg1157520d585841a691f4b598d9aac53adc95277ed710c7f1f5aaa59a89a8dca8ddf3e46d5241562f3316956a04ad8a33181d30cb01b1c4c9adb2f"
},
"ctorMsg": {
"function": "AC(123456A)",
"args": [
"AcctId:949392949233 "
]
},
"secureContext": "user_type1_c19a5f0b7e"
},
"id": 2
}
Here's the response for the query.
{
"jsonrpc": "2.0",
"error": {
"code": -32003,
"message": "Query failure",
"data": "Error when querying chaincode: Error:Transaction or query returned with failure: Received unknown function query"
},
"id": 2
}
Right now, I am trying out this tutorial, which is provided by IBM Bluemix:
https://github.com/IBM-Blockchain/learn-chaincode.
I have tried an init using their example and do invoke(successful) to suit my needs. I tried the Bluemix tutorial, which I mentioned earlier, and I am able to achieve what is stated in the documentation. Therefore, I decided to invoke something to suit my own needs. However, i am unable to query the person AC(123456A) or user_type1_c19a5f0b7e with showing of items such as "Year2015 Sem1", "IT1234:A", "IT3456:B+ " and etc . How can I query (the invoke) to suit my own needs?
Our understanding is that you are using an IBM Blockchain Starter Developer Network on IBM Bluemix. Using this environment, the "Learn Chaincode" tutorial (https://github.com/IBM-Blockchain/learn-chaincode) has been followed. We would like to confirm our understanding of your results when following the tutorial. Our understanding is that when following the tutorial, the Init, Invoke, and Query chaincode functions all operated as expected. Is the understanding correct that the tutorial as written could be followed successfully?
Then we understand that the example chaincode was modified to apply different logic. The Invoke for this modified chaincode that uses the AC(123456A) function with a user of user_type1_c19a5f0b7e appears to have been successful. However, a query that also used the AC(123456A) function was not successful. Is this understanding correct?
Could some additional details be provided so this can be considered further?
Did you write your own customized chaincode? If so, could this chaincode (including the AC(123456A) function definition) be provided?
Is the AC(123456A) function located in the same Go source file as the rest of the chaincode?
We imagine that the user named user_type1_c19a5f0b7e was registered since the Invoke did work. Were steps to register this user followed as noted in the "Secure Enrollment" section of the "Learn Chaincode" tutorial?
Can the AC(123456A) function both write values to the ledger (through the Invoke) and read values from the ledger (as is being attempted through the Query)?

Resources