Smooch: How to trigger postback when user clicks a button? - smooch

I have some questions about the postback button.
We are developing independent-built, own Web Messenger using Smooch.
I am making an API call using Smooch-core. ( like below )
this.smooch = await new SmoochCore({
keyId: SMOOCH_KEY_ID,
secret: SMOOCH_SECRET,
....
});
...
await this.smooch.appUsers.sendMessage(this.appId, this.userId, message);
The problem is that it works differently from our intent when we render and tap the button.
To create a button in the Messenger window, app maker sends a message with a postback type action,
receives the payload of the message from webhook,
and then renders the button and handles the click action according to our system policy.
Here is message code that app maker sends
{
"role": "appMaker",
"type": "text",
"text": "check in/out infos",
"actions": [
{
"text": "Check In Info",
"type": "postback",
"payload": "{\"text\": \"Check in info\", \"type\": \"start\", \"flow\": \"checkInOut\", \"message_id\": \"MESSAGEID001\", \"data\": {\"intent\": \"info_check_in\"}}"
},
{
"text": "Check Out Info",
"type": "postback",
"payload": "{\"text\": \"Check out info\", \"type\": \"start\", \"flow\": \"checkInOut\", \"message_id\": \"MESSAGEID001\", \"data\": {\"intent\": \"info_check_out\"}}"
},
{
"text": "Early Check In Info,
"type": "postback",
"payload": "{\"text\": \"Early check in\", \"type\": \"start\", \"flow\": \"checkInOut\", \"message_id\": \"MESSAGEID001\", \"data\": {\"intent\": \"info_early_check_in\"}}"
}
]
}
My system renders actions (buttons) of the message using ReactJS.
<ul className={b('button-group')}>
{
actions.map((action, index) => {
return (
<li
key={index}
onClick={this.onChoiceButtonClick(action)}
>
<span>{action.text}</span>
</li>
);
})
}
</ul>
Since I am handling the button click event in our system, I want to make the same action as tapping the postback button provided by Smooch.
(That is, "trigger": "postback" , like "trigger":"message:appUser" for smooch.appUsers.sendMessage )
How can I handle this?
Would greatly appreciate it if you kindly give me some advice. :)

You should call the triggerPostback method in response to the user clicking your custom button. According to the code snippet you posted above, you are calling a method onChoiceButtonClick. The implementation of that method should look something like this:
function onChoiceButtonClick(action) {
Smooch.triggerPostback(action._id);
}

Related

Unable to send message to end user (msteams) via Bot

Facing issue to send proactive message to the end user (msteams), via bot service,
I try using the bot framework python SDK, where I am getting the following error even for getting conversation id.
botbuilder.schema._models_py3.ErrorResponseException: Operation returned an invalid status code 'Unauthorized'
Hence I try to simulate calls via postman and rest API's, in here I am able to get conversation id successfully, but if I try to use that conversation id to further send a message via activities I am not able to do it. following is rest endpoint and payload. In here I am getting an error of incorrect payload.
https://smba.trafficmanager.net/apis/v3/conversations/8:orgid:949a3f72-b82c-4b89-b2de-9defbe6ae7cd/activities
{
"type": "message",
"recipient": {
"id": "29:1ZcsKdk0rsLmsywvI2SNQ2J7OIz"
},
"from": "bot",
"channelData": {
"notification": {
"alert": "true"
}
},
"text": "Hello world"
}
There was an issue with payload, I added BOT_ID along with name and able to successfully post message to end user. Following is working payload.
Payload:
{ "type":"message",
"recipient":{
"id":"29:1dUxQXVlH6QGByu1T9MR4p5g0c5URMaBtKqGU74C3zdowO78nPbuu2dg- qj9o02OkJ4MYXt2I-nxDgf9ga9EY5w"
},
"from":{
"id":"28:d7afe8c9-f0cd-434f-8906-be2b744229ac",
"name":"bot"
},
"channelData":{
"notification":{
"alert":"true"
}
},
"text":"Hello "
}

Connectwise Ticket API: Invalid ServiceNote Object

I've been trying to add a note to an existing ticket with the rest api
endpoint: cw.mycompany.com/v4_6_release/apis/3.0/service/tickets/1327224/notes
request body:
{
"text":"Test message"
}
However, I get the following response:
{
"code": "InvalidObject",
"message": "serviceNote object is invalid",
"errors": [
{
"code": "ServiceNote",
"message": "Please choose where to display the notes in order to save this record.",
"resource": "serviceNote",
"field": "detailDescriptionFlag, internalAnalysisFlag, resolutionFlag"
}
]
}
What do I need to add to my request to add the note to my ticket? I don't see anything in the ServiceNote Object that looks like a "display location" or something to that effect anywhere.
Thanks,
~Josh
Provide one of the "field" values listed in the error as a boolean; either detailDescriptionFlag, internalAnalysisFlag, or resolutionFlag.
Most likely you'll be using detailDescriptionFlag. An example payload for this would be:
{
'text' : 'Hello World',
'detailDescriptionFlag' : true
}
None of this is covered in their REST documentation for Create Service Note.

DialogFlow: Posting attchment to Facebook via Fullfillment via Firebase (inline) Cloud functions

I am setting up a Chatbot for my Facebook page with Google Dialogflow handling the conversations.
For a specific Intent, I need to send 2 responses.
A regular statement with User's name put in.
A Persistent menu with 3 buttons
I understand that for a single Intent, I can't send the first response via Fulfillment code and the 2nd response setup through Dialogflow console UI. Hence, I need to write code to send both the responses.
I am able to send the first Response. But couldn't get to send a Rich message content. The DialogFlow documents show snippets of code, but it is unclear how the snippets of code from different pages fit it.
Here is my code (just posting actionHandlers) in an attempt to send a statement and an Audio (https://dialogflow.com/docs/rich-messages#custom_payload)
const actionHandlers = {
'input.welcome': () => {
const speechText = 'Hi ' + userProfile['first_name'] + ', This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I\'d like to help you with your needs 😃';
const responsePayload = {
'speech': speechText,
'outputContexts': [{
'user-name': userProfile.first_name
}],
"data": {
"facebook": {
"attachment": {
"type": "audio",
"payload": {
"url": "http://incompetech.com/music/royalty-free/mp3-royaltyfree/Funk%20Game%20Loop.mp3"
}
}
}
}
};
sendResponse(responsePayload);
},
// The default fallback intent has been matched, try to recover (https://dialogflow.com/docs/intents#fallback_intents)
'input.unknown': () => {
sendResponse('I\'m having trouble, can you try that again?'); // Send simple response to user
}
};
The text response is working but the Audio is not. Am I doing the right way? Any help appreciated.
Update 1: Audio is working, after changing the mp3 link. But text response is not working.
Log of the object that is sent to response.json() in my Cloud function.
{
"speech": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs 😃",
"displayText": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs 😃",
"data": {
"facebook": {
"attachment": {
"type": "audio",
"payload": {
"url": "http://66.90.93.122/ost/death-note-original-soundtrack/bowkqzxs/01%20Death%20note.mp3"
}
}
}
},
"contextOut": [{
"user-name": "Saiyasodharan"
}]
}
In above code, I expect
displayText to be displayed immediately -> which is not working
audio response to happen -> This is now working, after changing the mp3 link
I believe I need to give the text response, audio response via data property. Let me try and update here.
If you use a payload for a given integration, the text of the response will be ignored. You'll need to add your message with the attribute text to the facebook payload for it to be surfaced in Facebook messenger. For example:
{
"contextOut": [
{
"user-name": "Saiyasodharan"
}
],
"data": {
"facebook": {
"attachment": {
"payload": {
"url": "http://66.90.93.122/ost/death-note-original-soundtrack/bowkqzxs/01%20Death%20note.mp3"
},
"type": "audio"
},
"text": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs 😃"
}
},
"displayText": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs 😃",
"speech": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs 😃"
}

Chatfuel redirect_to_blocks does not work

I have a problem with my chatfuel JSON API from my node JS app.
I try to catch an error and return a message + a redirect_to_block to be able to ask the user again.
My error detection works well and if I try to display a message only it works. My JSON is :
[{"text":"Please type again"}]
But I can't add a redirect_to_blocks to this (and I even loose the text message display).
I tried those solutions (and probably some more) but I think I didn't get the JSON structure :
// Solution 1
[{ "message": { "text": "Please type again" }, "redirect_to_blocks": ["When?"] }]
// Solution 2
[{ "messages": { "text": "Please type again" }, "block_names": ["When?"], "type": "show_block", "title": "go" }]
// Solution 3
[{ "text": "Please type again" }, "redirect_to_blocks": ["When?"] }]
And here is the block I want to add (i'm not even sure the name I have to give to the JSON)
Thanks !
Julian, workaround that works for me is returning from API following JSON:
{
"set_attributes": {
"redirectBlock": <your block name>
}
}
and build structure in Chatfuel as below:
Chatfuel flow
Now you have a dispatcher that allows you to map values from API to block titles.
I had your same issues,
I created a json request in my Flow that returns this json:
{ "redirect_to_blocks": ["Block name"] }
but Chatfuel never redirects to it.
I solved it creating a new block in "Automate" pane with same name and It works.
I know that it's passed much time since your question,
but I hope it can helps future issues.

Check if person answers call or get voice mail using ask fast

I use this api: Ask Fast, to communicate with my customers. I use this to call my customers to update them on the status of their order. I need to know if the customer has picked up the phone, or that I have reached their voice mail. In the documentation there is no such a method. Is there a way to know this? In both the scenarios the servers gives a 200 code back.
I make this call:
url: http://api.aks-fast.com/dialoghandler/rpc
{
"method": "outboundCallWithMap",
"params": {
"addressMap": {
"003110xxxxxxx": "me"
},
"url": "my url",
"accountID": "xxxxxxxxxxxxx",
"senderName": "me",
"subject": "test message"
}
}
There is no such method because the carries thinks that in both situations the phone is picked up. A work around would be to create interaction. For example: before giving the information ask the question: "I do not know if you are human can you press a button" if there is not button pressed for 10 seconds you know it is a voice mail. A way of achieving this would be:
Initial question json
{
"question_id":<some_id>,
"question_text":"I do not know if you are human can you press a button",
"type":" closed",
"url":"<referral url>",
"answers":[
{
"answer_id":<some_id>,
"answer_text":"Press one if you are human",
"callback":"The real question url"
}
],
"event_callbacks":[
{
"event":"timeout",
"callback":"i am not a human url or leave empty if you want to hang up"
},
],
"media_properties": [
{
"medium": "BROADSOFT",
"properties":
{
"TIMEOUT": "10s"
}
}
]
}
Here you ask if the customer would like to respond. If this does not happen the phone will be hang up and your url with the right action will be called.
In the TIMEOUT you can specify how long it will take for the timeout method to be called.
Hope this helps.