get started button for fb messenger in dialog flow - artificial-intelligence

I need some help regarding chatbot development. right now i am doing a project wherein im creating a chatbot using dialogflow and im testing it in FB messenger. one of the modules that i need to accomplish is to put a "get started" button to start a chat and a persistent menu in FB messenger. i've tried to search on how to do it but there's no specific tutorial on how to implement it in dialogflow. i never tried any code so far 'coz i don't know where should i put it. i hope someone out there will help me regarding this matter. thank you so much!

You can do these using Postman (free) but first you should have an Access Token
To get your page Access Token:
Head over to your Facebook App that you created for the bot on Facebook Developers
Go to Messenger --> Settings
Access Token Section
Generate an Access Token for your page
GET STARTED BUTTON
After you get your Access Token Go to Postman
Send a POST Request to: https://graph.facebook.com/v2.6/me/thread_settings?access_token=xxxxx
Replace xxxxx with your Access Token previously fetched
Go to Body and insert the following JSON
{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
{
"payload":"YOU PUT OPTIONAL PAYLOAD HERE"
}
]
}
PERSISTENT MENU
Send a POST Request to: https://graph.facebook.com/v2.6/me/messenger_profile?access_token=xxxxx
Replace xxxxx with your Access Token previously fetched
Go to Body and insert the following JSON (you can edit as you wish)
{
"persistent_menu":[
{
"locale":"default",
"composer_input_disabled":false,
"call_to_actions":[
{
"title":"Title 1",
"type":"postback",
"payload":"payload1"
},
{
"title":"Title 2",
"type":"postback",
"payload":"payload 2"
},
{
"title":"Title 3",
"type":"postback",
"payload":"payload 3"
}
]
}
]
}

Related

Approving or disapproving requests in one flutter app from another flutter app

So, I have created two applications, user and admin, using flutter. And both of them are in a single firebase project.
The Applications are investment-related. What I want to do is, Suppose a user sends an investment request from the user app. Another user in the admin app should be able to approve or disapprove the request and then the request status should be visible in the user app. Is there any way to do it?
What I tried: I created a new field in Firebase Realtime Database named Request Status. Then I passed a String Approved into it through the Admin app but it didn't work.
...
final investmentRequestsRef = database.child("Investment Requests");
...
void addData(String requestStatus) {
investmentRequestRef.set({
"Request Status": requestStatus,
});
}
...
Code of button that updates the status:
ElevatedButton(
...
onPressed: () {
addData("Approved");
},
...
)
What happens in realtime database when I do the method
You should try something like this...
DatabaseReference ref = FirebaseDatabase.instance.ref("Investment Requests/${requestID}");
await ref.update({
"Request Status": requestStatus,
});
This should work... I haven't seen your full code so I can't add anything else without more details about your code.
Use this official link of FlutterFire for reference.

How to create a case in a Salesforce Account using REST API and python Script

I need some help. I need to create a case in a Account with all the details basically, all the fields, using REST API but it I am not able to figure out, how to insert a record for creating a case.
Could you please guide me, how to create a case using REST API in Salesforce?
Do you use a library such as https://pypi.org/project/simple-salesforce/0.3/ or do you need to craft the REST messages manually?
You'd need to do it in 2 calls, login first (unless you have session id already) and then
POST to
https://yourinstance.my.salesforce.com/services/data/v48.0/sobjects/Case
with header
Authorization Bearer <session id goes here, sometimes called "access token" too>
and body
{
"Subject": "Hello world",
"Description": "Lorem ipsum dolor sit amet...",
"Origin":"Web",
"AccountId" :"0010g00001mbqU4"
}
should work like a charm (pass an account id value right for your org and you might have more fields to fill in).
So now "only" how to log in. That's a bigger topic and depends if it's a backend thing or you'll have a human interacting with it, maybe logging in to SF and then coming back to your org. There's bit of reading on that (simpler if you'd use SOAP API to log in)
For example this would work if I didn't redact all sensitive stuff
POST to
https://login.salesforce.com/services/oauth2/token
with header
Content-Type application/x-www-form-urlencoded
and body
grant_type=password
&client_id=(ask your admin for "connected app")
&client_secret=(ask your admin for "connected app")
&username=redacted%40example.com
&password=redacted
Should return
{
"access_token": "<session id here, use it as Authorization header in next calls>",
"instance_url": "<use this as base url of all next calls>",
"id": "<call GET to this (with the Auth header) to learn more about user",
"token_type": "Bearer",
"issued_at": "1593684589157",
"signature": "redacted"
}
Again - don't do it all by hand if you can, use one of Python libraries for Salesforce.
from simple_salesforce import Salesforce
sf = Salesforce(
username='user name of salesforce account',
password='password',
security_token='token')
Sample data
data ={
"Name" : "ABCD",
"Contact" : "123456789",
"Description":"Radio has damaged because of handling."
}
create record
x = sf.Account.create(data)

passing selected button value from fb messenger to dialog flow

I am failing to understand the simple passing of parameters to and fro via webhook. 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 guess you're missing few steps here. Before, I explain you what to do, be sure to know what a postback is! Postback, when tapped, the text is sent as a user query to dialogflow.com.
Step-1: I created an intent with custom payload as follows:
Step-2: Now, I created a new intent where I have entered user says as noeggs which is of type postback & payload as noeggs the in previous image.
Step-3: Save & test it in FB Messenger.
So basically, what has happened here is, when you click on Eggless button, postback as noeggs is sent as user query to dialogflow.com where there is an intent which matches user says with noeggs & sends response back.

"Resource not found for the segment" using Graph subscription beta

Im using the Microsoft Graph to get calendar event with application permission. It works perfectly. Now Im trying to set up a subscription to listen to event changes however the normal v1.0 do not suport this. However beta, at least in the description, say it works.
From the page: https://graph.microsoft.io/en-us/docs/api-reference/beta/api/subscription_post_subscriptions
"Note: the /beta endpoint allows Application permissions as a preview feature for most resources."
So I tried this with the URL:
https://graph.microsoft.com/beta/subscriptions
Sending in a json object like this:
{
"changeType":"created,updated,deleted",
"notificationUrl":"https%3A%2F%2FXXX.com%2Fo365.php",
"resource":"%2Fusers%2Fooom%40xxx.com%2Fevents",
"clientState":"1486588355561",
"expirationDateTime":"2018-11-20T18:23:45.9356913Z"
}
Doing this I get the result:
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment '/users/room#xxx.com/events'.",
"innerError": {
"request-id": "d9ca58b1-ee1f-4072-81d5-0f1a25dcdd45",
"date": "2017-02-08T21:26:51"
}
}
}
I have tried all types of combos in the resource but cant get it to work.
Anybody that have an idea on how to do this?
The value of json properties don't need to be url encoded. The resource also doesn't need a '/' in front of "users" (although this isn't what is causing your issue).
Try changing your JSON to:
{
"changeType":"created,updated,deleted",
"notificationUrl":"https://myurl.com/o365.php",
"resource":"users/person#myemail.com/events",
"clientState":"1486588355561",
"expirationDateTime":"2018-11-20T18:23:45.9356913Z"
}
Feel free to respond back if this doesn't address the issue.

How to add buttons to KIK bot to capture user input?

So, I have a KiK bot and want to add buttons to the bottom of the chat window to ask specific questions. The user clicks on one, which is taken as there response and processed as a message. The buttons then change again based on this response.
I've seen it in a lot of other KIK apps, but there's nothing in the KiK API that says how to do it!
Does anyone know how to create these response buttons in KIK? :)
What you're looking for are keyboards (specifically the Suggested Response Keyboard), you can read up on how to use them here: https://dev.kik.com/#/docs/messaging#keyboards
Adding my solution as it may help to someone:
function sendButtons() {
var arrResponse = [{ type: "text", body: "Summer" }, { type: "text", body: "Rainy" }, { type: "text", body: "Winter" }];
var sendingMessage = Bot.Message.text("Which Season do u like the most?")
bot.send(sendingMessage.addResponseKeyboard(arrResponse), recipient);
}
As you can see, you need to create an array of the input to show the user on keyboard.
And then attach this response array to the message.

Resources