Please find below details :
Intent with utterances
2.AWS lambda intent handler code
const DeliveryPercentage_Handler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return (
request.type === "IntentRequest" &&
request.intent.name === "DeliveryPercentage"
);
},
async handle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
const responseBuilder = handlerInput.responseBuilder;
let sessionAttributes =
handlerInput.attributesManager.getSessionAttributes();
var num2 = request.intent.slots;
if (num2) {
console.log("numb2");
console.log(JSON.stringify(num2));
output1 = "The sum of " + num2 + " and " + num2 + " is " + (num2 + num2);
}
// let dataResponse = await getShipmentInPercentage(1,"Delivery");
// let say = "Your delivery percentage is " + (dataResponse.percentage);
let say = "test " + num2.numbnew.value;
return responseBuilder
.speak(say)
.reprompt("try again, " + say)
.getResponse();
}
};
3.Getting the slots with name but not the value in it
END RequestId: a260e0f4-69a5-47a0-bcb5-91020a1b94f6
REPORT RequestId: a260e0f4-69a5-47a0-bcb5-91020a1b94f6 Duration: 0.91 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 75 MB
START RequestId: 87e8761d-e725-43b6-bb83-a4ca93b3d6c3 Version: $LATEST
2020-02-28T12:41:15.391Z 87e8761d-e725-43b6-bb83-a4ca93b3d6c3 numb2
2020-02-28T12:41:15.391Z 87e8761d-e725-43b6-bb83-a4ca93b3d6c3
{
"numbnew": {
"name": "numbnew",
"confirmationStatus": "NONE"
}
}
END RequestId: 87e8761d-e725-43b6-bb83-a4ca93b3d6c3
REPORT RequestId: 87e8761d-e725-43b6-bb83-a4ca93b3d6c3 Duration: 247.16 ms Billed Duration: 300 ms Memory Size: 128 MB Max Memory Used: 76 MB
Slot log value is missing
** {
"numbnew": {
"name": "numbnew",
"confirmationStatus": "NONE"
}
}
**
Any help would be appreciated
Thanks in advance !
Utterances that you have set for your intent DeliveryPercentage is
"What is the delivery percentage {numbnew}"
where {numbnew} is your intent slot which will collect value for above utterances, I guess when you are testing this skill you are only saying "What is the delivery percentage" instead you need to say "What is the delivery percentage 80" or any number you want!
then you will get following response in your request
"slots": {
"numbnew": {
"name": "numbnew",
"value": "80",
"confirmationStatus": "NONE",
"source": "USER"
}
}
Suggestion, if you are trying to collect percentage data from user, then try to make this question "What is the delivery percentage" in response builder of AWS lambda intent handler and make Utterances with something like this "My percentage is {numbnew}"
Related
I am creating a subscription in the cloud composer code with a dynamic subscription name. After that I have a PubSubPullSensor operator. Before this task starts I manually send a message to that topic with some attribute so that it can go that subscription. But after I publish a message in the topic, it takes a long time for the PubSubPullSensor, sometime more than 19 minutes.
Is it that attribute which is causing the issue of taking long time?
How can I resolve this?
Please let me know.
with DAG(
"pubsub_trigger_dy_sub_2",
schedule_interval=None,
catchup=False,
default_args=default_arguments,
) as dag:
def samplePythonFn():
print("Getting called from cloud composer")
def _createSubscription(**kwargs):
hook = PubSubHook()
subscriptionName = "airflow-test-" + str(uuid.uuid4())
application = "LumiPortal"
result = hook.create_subscription(
topic=topic,
subscription=subscriptionName,
expiration_policy={
"ttl": Duration(seconds=24*60*60)
},
labels={
"source": "dag"
},
filter_='attributes.correlid = "' + subscriptionName + '"'
#f'attributes.correlid = "{subscriptionName}"'
)
ti = kwargs['ti']
print(subscriptionName)
print(application)
ti.xcom_push(key='Subscription_1', value=subscriptionName)
return subscriptionName
pull_messages_1 = PubSubPullSensor(
task_id="pull_first_messages",
ack_messages=True,
max_messages=1,
return_immediately=True,
project_id=project_id,
subscription="{{ task_instance.xcom_pull(task_ids='CreateSubscription_1') }}",
dag=dag
)
start = DummyOperator(task_id='start')
create_subscription_task_1 = PythonOperator(
task_id='CreateSubscription_1',
python_callable=_createSubscription,
provide_context=True,
)
call_stored_procedure_load = BigQueryInsertJobOperator(
task_id="call_stored_procedure",
configuration={
"query": {
"query": "CALL `amexpoc1.bqTableFullRefresh`('{}','{}','{}')".format(dataset, stage_table,main_table),
"useLegacySql": False,
}
}
)
delete_subscription_task_1 = PubSubDeleteSubscriptionOperator(
task_id='DeleteSubscription_1',
subscription="{{ task_instance.xcom_pull(task_ids='CreateSubscription_1') }}"
)
def pullxcomm1(**kwargs):
ti = kwargs['ti']
fetched_first_message = ti.xcom_pull(key='return_value', task_ids=['pull_first_messages'])
print(fetched_first_message)
return fetched_first_message
pullxcomm_first_message = PythonOperator(
task_id='pull_First_xcomm',
python_callable=pullxcomm1,
provide_context=True,
dag=dag
)
end = DummyOperator(task_id='end')
In react, I have the following code which is running offline. I obviously found it.:
async function deleteMessage() {
toDelete = await DataStore.query(Message, c => c.id("eq","4faebf3b-f89a-4e34-978a-0fea611897e0"))
alert("toDelete: " + !toDelete ? toDelete : toDelete.length )
if (!toDelete || (toDelete !== undefined && toDelete.length == 0))
{
alert("Nothing to delete")
return
}
alert("Deleting " + toDelete.length + " records.")
alert("id for 0 = " + toDelete[0].id + " title: " + toDelete[0].title + " color: " + toDelete[0].color + " createdAt: " + toDelete[0].createdAt)
await DataStore.delete(toDelete);
alert("after delete")
// updateFormState(initialState)
}
toDelete has all the fields correct and is being displayed in the alert before the actual delete, so toDelete should be the correct model.
The one alert is saying: Deleting 1 records.
The next alert says: id for 0 = 4faebf3b-f89a-4e34-978a-0fea611897e0 title: aaasdfasdf color: #6c2f2f createdAt: undefined
But it never returns from the delete and I am getting the error:
Unhandled Rejection (Error): Object is not an instance of a valid model
DataStore.<anonymous>
C:/Projects/React/src/datastore/datastore.ts:897
894 | sortPredicate = ModelSortPredicateCreator.createFromExisting(modelDefinition, paginationProducer.sort);
895 | }
896 | return {
> 897 | limit: limit,
| ^ 898 | page: page,
899 | sort: sortPredicate,
900 | };
View compiled
What am I missing?
Also, the model is:
type Message #model {
id: ID!
title: String!
color: String
createdAt: String
}
Thanks.
Figured it out.
Change toDelete = await DataStore.query(Message, c => c.id("eq","4faebf3b-f89a-4e34-978a-0fea611897e0"))
to
toDelete = await DataStore.query(Message, "4faebf3b-f89a-4e34-978a-0fea611897e0"))
The first example returns an array of objects.
The second example returns an object.
The DataStore.delete() expects an object not an array of objects. I was passing an array of objects.
DataStore.delete(toDelete) would work with the 2nd example but not the first since that was an object.
If I am using the first example would have to use:
DataStore.delete(toDelete[0])
I have a question about adding the avatarUrl from an user mentioned. I've done the code but it doesn't show the image when sending the embed. There's also not error in the console.
const user = message.mentions.users.first();
var mention = "<#" + user.id + ">"
var userCreated = user.createdAt.toString().split(" ");
var userJoined = user.userJoined
const Embed = new Discord.MessageEmbed()
.setTitle(user.tag)
.setDescription(mention)
.setColor("#b60303")
.addFields(
{ name: "Registered at", value: userCreated[1] + " " + userCreated[2] + ", " + userCreated[3]},
{ name: "ID", value: user.id, inline: true}
)
.setImage(message.avatarURL)
.setTimestamp()
.setFooter("ID: " + user.id)
message.channel.send(Embed)
}```
Messages don't have avatar URLs, and in Discord JS v12, avatarURL is a method.
.setImage(message.author.avatarURL())
This is a question about Gatling version 3.3
I would like to save a few keys from a json response and concatenate them, so that I can reuse them in the body of the next request.
What I get from the server from the get request is this:
{
"result": [{
"label": "Work",
"addr1": "212 Stephenville St",
"addr2": "",
"city": "Massena",
"zip": "13668",
"country": "US",
"region": "US-NY",
"additionalInfo": "",
"building": "",
"floor": "",
"room": "",
"phone": ""
}
]
}
What I need to have is a variable with addr1 + zip + region + country, meaning:
"212 Stephenville St" + " " + "13668" + " " + "US-NY" + " " + "US"
This is what I was trying to do:
var address0: String = " "
def getAddresses() = {
exec(http("GET /addresses")
.get("/addresses")
.check(status.is(200))
.transformResponse {
(session, response) =>
if(response.status.code == 200) {
val jsonResponse: JsValue = Json.parse(response.body.string)
address0 = (jsonResponse \ "result" \ 0 \ "addr1").as[String] + (jsonResponse \ "result" \ 0 \ "zip").as[String] + (jsonResponse \ "result" \ 0 \ "region").as[String] + (jsonResponse \ "result" \ 0 \ "country").as[String]
session.set("address1", address0)
response
} else {
response
}
})
.pause(1)
.exec {session => println(session); session}
}
I have confirmed that address0 inside the transformResponse block has the value I need, but it is not available outside. I also tried session.set("address1", address0) thinking that it can add a new attribute but it is not present when I do println(session).
I wonder if someone can provide any help on how to make available the value of address0 outside this block so that I can reuse it in the next request?
By the way I know I can do the following and it works.
def getAddresses() = {
exec(http("GET /addresses")
.get("/addresses")
.check(status.is(200))
.check(jsonPath("$.result[0].addr1").saveAs("addr1"))
.check(jsonPath("$.result[0].zip").saveAs("zip"))
.check(jsonPath("$.result[0].region").saveAs("region"))
.check(jsonPath("$.result[0].country").saveAs("country")))
.pause(1)
.exec {session => println(session); session}
}
But I would prefer to do it within the transformResponse block if possible
Thanks in advance.
You can probably do this with transformResponse, but I'm not sure it's the best way. What's going wrong in your example is that transformResponse is for modifying the response prior to running checks - it takes the response and the session, and returns a response. Editing the session inside the block doesn't work as sessions are immutable, and you don't get to return the session.
So what you need to do is parse the response as JSON (as you're doing), then add your newly constructed address back into the response and return it before getting the value into the session via check calls.
What would be easier would be to get all the component values via checks, then assemble them into the desired composite and store that into the session - either in a session function or as part of a check transform. This way you wouldn't need to mess around with any custom JSON parsing / construction at all.
def getAddresses() = {
exec(http("GET /addresses")
.get("/addresses")
.check(status.is(200))
.check(jsonPath("$.result[0].addr1").saveAs("addr1"))
.check(jsonPath("$.result[0].zip").saveAs("zip"))
.check(jsonPath("$.result[0].region").saveAs("region"))
.check(jsonPath("$.result[0].country").saveAs("country"))
)
.exec(session => session.set("address", session.get("addr1").as[String] + session.get("zip").as[String] + session.get("region").as[String] + session.get("country").as[String]))
I am using Microsoft Graph for fetching user information, namely "List users" API.
Following is the code for accessing the user information :
ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(resourceId, clientCred);
string token = authenticationResult.AccessToken;
Debug.WriteLine("token=" + token);
var responseString = String.Empty;
string[] scopes = { "User.Read" };
using (var client = new HttpClient())
{
string requestUrl = "https://graph.microsoft.com/v1.0/users?$select=id,givenName,surname";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
Debug.WriteLine(request.ToString());
HttpResponseMessage response = client.SendAsync(request).Result;
responseString = response.Content.ReadAsStringAsync().Result;
Debug.WriteLine(responseString);
}
Output :
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,givenName,surname)",
"value": [
{
"id": "000000000-0000-0000-000-000000000",
"givenName": "XXX",
"surname": "XXX"
}, {
"id": "000000000-0000-0000-000-000000000",
"givenName": "XXX",
"surname": "XXX"
}
]
}
How to the get user group ?
You can call the user: getMemberGroups API action for a user to get their groups:
You need to make a request like so:
POST https://graph.microsoft.com/v1.0/users/user-id-here/getMemberGroups
Content-type: application/json
Content-length: 33
{
"securityEnabledOnly": true
}
The securityEnabledOnly parameter defines if it should only return security groups. Setting it to false will also return the user's Office 365 group memberships for example.
An alternative is to use the memberOf navigation property:
GET https://graph.microsoft.com/v1.0/users/user-id-here/memberOf
This returns the groups and directory roles the user is a direct member of.