In Amazon Lex, How to get the post message from Facebook - facebook

I am using following code to post message back to Amazone Lex
....
var objItem = {
"title": `(£${item.price} pw) ${item.street_name}`,
"image_url": item.image_url,
"subtitle": `${item.displayable_address}`,
"buttons": [
{
"type": "web_url",
"url": `${item.details_url}`,
"title": "View"
}, {
"type": "postback",
"title": "Book Item",
"payload": {vid:"CAL00002"}
}
]
}
....
When the button "Book Item",is clicked,currently, the message "payload": {vid:"CAL00002"} will be sent back to Amazon Lex. it seems that Amazon Lex don't know this message, so I can NOT get this object in Amazon Lambda functions. here I am using Amazon Lex as AI to learn user's intent, and then all business logic is implemented in Amazon Lambda. in this situation, how can I post message back to Lambda? or Is there a way to post structured message back to Lex?

I'm not sure how you are sending message back to Lambda, but I'm using AWS SDK to do this. Whatever information I want Lambda to get, I put it in sessionAttributes to pass.

Related

how to update a ticket in Zammad via API

My goal is to create a ticket in Zammad using the API and then to update it (for.
the reference for such basic tasks is here
I am using Postman to send requests.
I use the bearer token authentication, the token has been generated for a user who is ticket.agent (and he is admin too).
I manage to succesfully create a ticket by doing a post request to
https://myzammadinstance.com/api/v1/tickets
and with this body:
{
"title": "Ticket generated from API - my test",
"group": "Users",
"article": {
"subject": "My Subject",
"body": "My body",
"type": "note",
"internal": false
},
"customer": "my#email.address",
"user": "my#email.address",
"note": "my notes"
}
This succesfully creates a ticket (with a given ID, let's say 1990).
Now i would like to update this ticket, so "replying from API".
I do a post request to
https://myzammadinstance.com/api/v1/tickets
and with this body:
{
"id": 1990,
"title": "updated title",
"group": "Users",
"state": "open",
"customer_id": 12,
"priority": "3 high",
"article": {
"subject": "some subject of update",
"body": "some message of update"
}
}
This executes but does not append a reply to my ticket 1990 but it generates a new ticket (with id 1991 and title "updated title").
I do not want to create a new ticket but just reply to an existing ticket.
May i misunderstood something but i double checked many times the documentation and the request body.
Anyone could give an hand please?
UPDATE: as stated in the comments is seems i should use
https://myzammadinstance.com/api/v1/tickets/1990
but this does not work: a new ticket is not created but the response has an error:
{
"error": "No route matches [POST] /api/v1/tickets/1990"
}
SOLUTION
The problem was in PUT vs POST, by using PUT and this endpoint
https://myzammadinstance.com/api/v1/tickets/1990
i managed to reply to the ticket.
To update the ticket you would need to use this endpoint:
PUT /api/v1/tickets/{id}
https://docs.zammad.org/en/latest/api/ticket.html#update

message template are not working in kore.ai

I want to display list to the user with kore.ai, currently, I am using telegram but the template is not working it is just showing the code.
var message={
"type": "template",
"payload":
{
"template_type": "button",
"text": "What do you want to do next?",
"buttons":
[{
"type": "web_url",
"title": "Show Website",
"url": "https://petersapparel.parseapp.com"
},
{
"type": "postback",
"title": "Start Chatting",
"payload": "USER_DEFINED_PAYLOAD"
}
]
}
}
print(JSON.stringify(message));
Expected result:
Some templates are channel specific which means not every end channel supports each and every templates . Please try with different channels such as Web or Facebook messenger, your template will be supported.
You will need to make sure that the template structure is supported by the channel.
The channels usually have the template structures defined on their technical documentation.
Please select the appropriate channel on the bot builder and then use the template structure as they have defined.

Facebook Messenger button error: "Action Unsuccessful There was an error delivering your message..."

I've checked the other questions about this error and the only solutions offered are "subscribe to the messaging_postbacks at Messenger -> Settings -> Webhooks -> Edit events.
You can see here that I have done this since the original setup of my bot, and I have even re-subscribed to it since:
But I am still getting this error:
I am logging any request that comes into my webhook and there is no activity, even though clicking the button, shows the payload value in blue as if I typed and sent it as a message. Then the popup "Action Unsuccessful" shows, and my bot doesn't receive anything.
Here is the response to FB with the button attachment elements:
{
"recipient": {
"id": "xxxxxxxxxxx"
},
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "list",
"top_element_style": "compact",
"elements": [{
"title": "transfer",
"subtitle": null,
"image_url": "http://xxxxxxx",
"buttons": [{
"type": "postback",
"title": "transfer",
"payload": "transfer"
}]
}, {
"title": "hourly",
"subtitle": null,
"image_url": "http://xxxxxxxx",
"buttons": [{
"type": "postback",
"title": "hourly",
"payload": "hourly"
}]
}]
}
}
}
}
The Page Access Token just needed to be updated in the webhook. Probably to apply the latest permissions that include messaging_postbacks.
Go back to developer app dashboard. Select Messenger >> Settings.
Scroll down to the "Token Generation" section:
Select your page from the dropdown, and copy the new access token for use in your webhook.
Found a lot of similar questions and no clear answers. So I hope this saves someone the days of headache it caused me.

storing values from fb messenger bot into dialog flow

i am trying to build a simple bot using dialog flow and fb messenger. i have requirement to show two buttons to the end user to pick a cake type. i am able to show the options using the below custom response:
{
"facebook": {
"attachment": {
"type": "template",
"payload": {
"template_type": "button",
"text": "What kind of cake would you like?",
"buttons": [
{
"type": "postback",
"payload": "witheggs",
"title": "Contain Eggs"
},
{
"type": "postback",
"payload": "noeggs",
"title": "Eggless"
}
]
}
}
}
}
once user tap one of the two buttons then how do i set it to some variable in dialog flow and then ask next set of question?
I don't know what language you're using but here's what you're looking for:
The payload part is returned by api.ai as resolvedQuery when the user clicks any button.
For example, if the user clicks on Contain Eggs, api.ai will return witheggs through the resolvedQuery node of the json.
Does that help? Feel free to ask if there's anything else.

Wit.ai node package buggy

I was working with wit.ai today. I was using the node-wit module. But the responses I was acting were very weird.
When I used the node-wit module. I got the response as -
{
"msg_id": "0f4rOWRXQMIhVuf5i",
"_text": "what is your name",
"entities": {
"intent": [{
"confidence": 0.9425254893432,
"value": "get_name"
}]
}
}
Whereas when i used the cURL command to get the response the response was very different.
{
"msg_id": "0KJdIPedYbYwWOgOL",
"_text": "what do you do",
"entities": {
"intent": [{
"confidence": 0.97713342030998,
"value": "get_job"
}]
}
}
Can anyone tell why this is happening or if I am implementing the function wrong?
Are you using the same service, there are two services, one for conversations/stories and other for messages.
if that is not the reason try to check the context and take a look on the log section inside wit.ai web app