Is there any code (example) for creating persistent menu with microsoft bot framework c# ?
Is there any code for creating persistent menu with microsoft bot framework c# ? I found this : https://satwikkansal.wordpress.com/2016/08/25/adding-menu-and-buttons-to-your-messenger-bot/ But i'm using c# language .... so it would be excellent if is there any example written in c#
Not out of the box - curl is just making a HTTP Post to the FB API ...
Why don't you just Postman or Fiddler (or write some c# code) and create the necessary POST request - we used that method with great success.
Agree that it would be nice to add this to the emulator or even the bot framework portal. PS. Remember that you would have to 'catch' these 'global' commands as they may appear in any dialog/conversation you are having.
@lonche Hi, I'm having the same difficulty. Were you able to make the menu in C #? Best regards
@krconnect Yes. I made persistent menu. It is more difficult if you want to make POST request to Facebook using c#. If you want to make persistent menu, use this : https://developers.facebook.com/docs/messenger-platform/messenger-profile/persistent-menu and (ex. fiddler).
@lonche This documentation I already read, but I have not yet been able to understand how to create a drop down menu in C #. Thanks for the answer, I'll search more.
Hi Guys
Don't see what the issue is ? - Just do it via fiddler/Postman or whatever.
If you really want c# code -> use webclient and upload the data as specified in the links (substitute the curl for the webclient code).
To help you out I made you a quick sample using the FB Get started payload (which you need for the persistent menu) http://rextester.com/PGZ32787
Code:
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Net;
using System.Net.Http;
using System.Dynamic;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
String PAGE_ACCESS_TOKEN = "MYTOKEN"; //your facebook app token
//Build JSON required - Or use a string , copy+paste
dynamic Data = new ExpandoObject();
Data.get_started = new ExpandoObject();
Data.get_started.payload = "GET_STARTED_PAYLOAD";
Console.WriteLine("About to send : " + Newtonsoft.Json.JsonConvert.SerializeObject(Data));
using (WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/json";
var result = client.UploadString(
"https://graph.facebook.com/v2.6/me/messenger_profile?access_token=" + PAGE_ACCESS_TOKEN,
Newtonsoft.Json.JsonConvert.SerializeObject(Data)
);
Console.WriteLine("Result : " + result);
}
}
}
}```
If you can't see how to do the rest using this method then I'm not sure how we can assist further.
Cheers
@leroibeukes Thank you my friend!!!!! Now you've cleared the way! Many, many thanks!
@leroibeukes Many thanks, you could also share for Persistent Menu. please. in C#
Can anyone please help share code in c# for persistent menu? Thanks in advance.
I understood the process, but when I went to perform I could not. I'm still trying to build this menu that looks so simple, but it's not!
Hi Guys ....
Ok... I'll help you out and provide you with some sample code --- Expect it in the next day or two.
Cheers Le Roi
@leroibeukes .. please share the code.
Sorry guys - been travelling , will get to it in the next day or two
tks
Similar to last one - just build the structure...
Note did not test this very well.
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Net;
using System.Net.Http;
using System.Dynamic;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
String PAGE_ACCESS_TOKEN = "MYTOKEN"; //your facebook app token
//Build JSON required - Or use a string , copy+paste
dynamic Data = new ExpandoObject();
Data.persistent_menu = new ExpandoObject();
Data.persistent_menu = new []
{
new { locale = "default",
composer_input_disabled = false,
call_to_actions = new []
{
new { type = "postback",
title = "Menu Free Text",
payload = "menu1",//This is what the bot will receive
},
new { type = "postback",
title = "Menu Free Text2",
payload = "menu2",
},
/* DIFFERENT MENU STRUCTURE */
/*
new {
type = "nested",
title = "More",
call_to_actions = new []
{
new { type = "web_url",
title = "CLICK ME",
url = "https://SomeURLThatWasWhiteListedINYOURFBDEVELOPERPROFILE.com",
webview_height_ratio= "full",
messenger_extensions = true
}
}
}*/
}
}
};
Console.WriteLine("About to send : " + Newtonsoft.Json.JsonConvert.SerializeObject(Data));
using (WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/json";
var result = client.UploadString(
"https://graph.facebook.com/v2.6/me/messenger_profile?access_token=" + PAGE_ACCESS_TOKEN,
Newtonsoft.Json.JsonConvert.SerializeObject(Data)
);
Console.WriteLine("Result : " + result);
}
}
}
}
Perfect! Menu created !!! Now I'm trying to get the return from the menu click!
Awesome- please let us know how you go .
You should receive as the payload "menu1" when you click the "Menu Free Text" button.
Use this to figure out which action to do.
Cheers