How to add Response Card in Lex using PutIntent method? - aws-sdk

I am trying to add a Response Card in lex using putIntent(). In AWS the putIntent method accepts responseCard as a String but how to add title, subTitle, ImageUrl, button values, and button names at the time of creating an Intent using response card parameter through putIntent?
So can anyone please help me to solve the issue. Provide a sample input where response card as String which can contain the above attributes. Thank you in advance.
"slots": [
{
"description": "string",
"name": "string",
"priority": number,
"responseCard": "string",
"sampleUtterances": [ "string" ],
"slotConstraint": "string",
"slotType": "string",
"slotTypeVersion": "string",
"valueElicitationPrompt": {
"maxAttempts": number,
"messages": [
{
"content": "string",
"contentType": "string",
"groupNumber": number
}
],
"responseCard": "string" --(how to pass title, imageUrl and other attributes)
}

Looks like you got the correct slots portion of the full response format from Lex API PutIntent.
The responseCard format can be found at Lambda Input Response Format
"responseCard": {
"version": integer-value,
"contentType": "application/vnd.amazonaws.card.generic",
"genericAttachments": [
{
"title":"card-title",
"subTitle":"card-sub-title",
"imageUrl":"URL of the image to be shown",
"attachmentLinkUrl":"URL of the attachment to be associated with the card",
"buttons":[
{
"text":"button-text",
"value":"Value sent to server on button click"
}
]
}
]
}
Assuming you create that responseCard object in the format above as a variable named responseCard, then to make that object a string to pass in PutIntent try:
JSON.stringify(responseCard) if using Node.js, or
json.dumps(responseCard, separators=(',',':')) if using Python.

Related

Azure Data Factory - Teams Message Card including variable results

I have a teams message card that I post using a web activity.
Currently, I do a lookup to determine whether or not I post the results, those results are stored in a variable, like so;
I want to include the results held in "Set variable" within my teams message, this will output the following as an array;
Using the web body, in expression builder, how can I include the values stored in the variable within my message, here is what I have generated so far;
{
"#type": "MessageCard",
"#context": "https://schema.org/extensions",
"summary": "This is the summary property",
"themeColor": "800000",
"sections": [
{
"heroImage": {
"image": "https://messagecardplayground.azurewebsites.net/assets/FlowLogo.png"
}
},
{
"startGroup": true,
"title": "**Checks - Requires Investigation**",
"facts": [
{
"name": "Date submitted:",
"value": "06/27/2017, 2:44 PM"
},
{
"name": "Details:",
"value": "The validation checks are hilighted below; "
},
{
"name": "Results:",
"value": "Include the output here"
},
{
"name": "Support Document:",
"value": "[Click here](https://dev.azure.com/supportDocument)"
}
]
}
]
}
You can use String interpolation to include the value of your variable (array). Please look at the following demonstration:
I have used a fake API in my web activity where I use PUT method. The following is the request body that is needed to be passed to the API.
{
"name": "morpheus",
"job": "leader"
}
Instead of using static data, if I want to use dynamic content (lets say, for 'name') i.e., use the result of my variable in the web body, we can do it in the following way. In the following, the variable req_name has value morpheus.
{
"name": "#{variables('req_name')}",
"job": "leader"
}
Now since you have the required result, which should be used in web body, stored in your variable, you can change your body as follows in the expression builder:
{
"#type": "MessageCard",
"#context": "https://schema.org/extensions",
"summary": "This is the summary property",
"themeColor": "800000",
"sections": [
{
"heroImage": {
"image": "https://messagecardplayground.azurewebsites.net/assets/FlowLogo.png"
}
},
{
"startGroup": true,
"title": "**Checks - Requires Investigation**",
"facts": [
{
"name": "Date submitted:",
"value": "06/27/2017, 2:44 PM"
},
{
"name": "Details:",
"value": "The validation checks are hilighted below; "
},
{
"name": "Results:",
"value": "#{variables('<your_variable_name>')}"
},
{
"name": "Support Document:",
"value": "[Click here](https://dev.azure.com/supportDocument)"
}
]
}
]
}
NOTE:
You can always check the debug input to check whether the body you are passing is the correct format.
If it is not, then you can manipulate the variable as required to convert it to required format and then include its value as demonstrated above using String Interpolation (#{......}).

jmeter: I want to extract 2 values from 2 different json objects where 1 json object will validate my condition & other value I want to extract

My JSON Response is :
{
"results": [
{
"attributes": [
{
"format": "internal",
"name": "resourceid",
"type": "STRING",
"value": "56B15190000015E85E57923F0000033B"
},
{
"format": "attribute",
"name": "ds6w:identifier",
"type": "string",
"value": "ald7_al"
}
]
},
{
"attributes": [
{
"format": "internal",
"name": "resourceid",
"type": "STRING",
"value": "56B15190000015E85E578B1F000001B6"
},
{
"format": "attribute",
"name": "ds6w:identifier",
"type": "string",
"value": "fbh1"
}
]
},
{
"attributes": [
{
"format": "internal",
"name": "resourceid",
"type": "STRING",
"value": "56B15190000015E85E578F7800000211"
},
{
"format": "attribute",
"name": "ds6w:identifier",
"type": "string",
"value": "u89cf"
}
]
}
]
}
I want to get '56B15190000015E85E57923F0000033B' where value='ald7_al'
So basically within a jsonarray I have jsonobjects, and for single jsonobject I have two jsonobjects where secong jsonobject will validate my condition param and I want value from first jsonobject
For getting result to solve condition check I have used
JSON extractor expression as -> $..attributes[?(#.value==ald7_al)] which is giving me second json block but I want value from first json block.
Please help me if you have any inputs.
Thanking you in advance for your help!
As of JMeter 5.2.1 this it not possible with built-in JMeter components
JSON Extractor cannot do this due to underlying Jayway JsonPath issue 287
JSON JMESPath Extractor cannot do this due to underlying JMESPath issue 22
So you're left with JSR223 PostProcessor and Groovy language, example code which should resolve your issue would be something like:
def results = new groovy.json.JsonSlurper().parse(prev.getResponseData()).results
0.upto(results.size() - 1, { index ->
def attributes = results[index].attributes
if (attributes[1].get('value').equals('ald7_al')) {
vars.put('value', attributes[0].get('value'))
}
})
Add it as a child of the request which returns the above JSON and if everything goes well you will able to access the value you're looking for as ${value} where required.
More information:
Apache Groovy: Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

How to enter array type value for angular schematics

I'm learning Angular Schematics and have some problems regarding array type input.
When I am prompted to enter a value and press enter the value disappears. What is the correct way of entering an array value?
My schema.json is the following:
{
"$schema": "http://json-schema.org/schema",
"id": "HelloWorldSchematics",
"title": "Hello World Options Schema",
"type": "object",
"properties": {
"listName": {
"type": "string",
"description": "The name of the list.",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What's the name of list"
},
"colNames": {
"type": "array",
"items": {
"type": "string"
},
"description": "The name of the columns.",
"x-prompt": "What's the name of columns"
}
},
"required": [
"listName",
"colNames"
]
}
I was only able to enter a value using the flag. Following your example, you can enter values like this:
schematics ./collection.json:HelloWorld --listName User --colNames={id,firstName}
Notice that there is no space between the elements of the array.
The following WOULD NOT WORK:
schematics ./collection.json:HelloWorld --listName User --colNames={id, firstName}

Stringify JSON in Logic App

We are sending messages to a service bus using a logic app. These messages will later be consumed by another service, the service expects the message content to be a string - essentially a stringified JSON object, with escape characters.
We are not able to find a method to stringify a JSON object in Logic Apps. Even if we explicitly provide a escaped string the logic app itself detects that it's stringified JSON and unescapes it and then sends it as a JSON object. We don't want that, we simply want it to send the string as it is. We have already tried changing the content type to text/plain, it does not work. The logic app always sends the unescaped string as JSON.
This post on MSDN: https://social.msdn.microsoft.com/Forums/office/en-US/e5dee958-09a7-4784-b1bf-facdd6b8a568/post-json-from-logic-app-how-to-escape-data?forum=azurelogicapps is of no help because doing this will violate the request contract of the message consuming service
Do you need the stringified message to include opening and closing double quotes?
I've tried this and it worked for me.
I have my JSON object as an output of a compose
Then, I initialised a variable with the Base64 encoded value of the escaped stringified JSON (you need to add ALL the proper escaping required,
mine was just a PoC)
Then, you send the variable already in Base64 to Service Bus. (You need to remove the encoding on that action).
"actions": {
"Compose_JSON_Object": {
"inputs": {
"message": "I want this as a string"
},
"runAfter": {},
"type": "Compose"
},
"Initialise_Variable_with_Stringified_JSON_Base64_Encoded": {
"inputs": {
"variables": [
{
"name": "jsonAsStringBase64",
"type": "String",
"value": "#base64(concat('\"', replace(string(outputs('Compose_JSON_Object')), '\"', '\\\"'), '\"'))"
}
]
},
"runAfter": {
"Compose_JSON_Object": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Send_message": {
"inputs": {
"body": {
"ContentData": "#variables('jsonAsStringBase64')",
"ContentType": "text/plain"
},
"host": {
"connection": {
"name": "#parameters('$connections')['servicebus']['connectionId']"
}
},
"method": "post",
"path": "/#{encodeURIComponent(encodeURIComponent('temp'))}/messages",
"queries": {
"systemProperties": "None"
}
},
"runAfter": {
"Initialise_Variable_with_Stringified_JSON_Base64_Encoded": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
This way, I got the message stringified.
HTH

how to extract the JSON schema (sub schema) of a property from complete object json schema

I need a help regarding schema extraction by property.
For example i have a JSON schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "A simple address format",
"type": "object",
"properties": {
"street-name": { "type": "string" },
"locality":{ "type": "string" },
"region": { "type": "string" },
"postal-code": { "type": "int" },
"country-name": { "type": "string"}
},
"required": ["locality", "region", "country-name"]
}
I have an use case, where i need to extract the schema corresponding to each property and send to another service, where it will do validation against the value and save in database. Here is the sample object i need to send to another service.
{
"propertyName": "street-name",
"value": "19, Canton street",
**"schema": { "type": "string" }**
}
The questions is,
how we extract the schema for a particular property from a give JSON schema??
Given the property path, Is there any nodejs module exists to do this schema extraction? or if there is any other solutions exists ?
Because this is very simple scenario, but if we have array, anyOf, OneOf type its getting complicated;
Thanks in advance ! Please let me know if the question is not clear !
sadish