Facebook menu
Facebook menu doesn't work for me.
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type" : "call_to_actions",
"thread_state" : "existing_thread",
"call_to_actions":[
{
"type":"postback",
"title":"Show Help",
"payload":"Show Help"
},
{
"type":"postback",
"title":"Show Sources",
"payload":"Show Sources"
},
{
"type":"postback",
"title":"Add Source",
"payload":"Add Source"
},
{
"type":"postback",
"title":"How to Search?",
"payload":"How to Search?"
},
{
"type":"postback",
"title":"Sign Out",
"payload":"Sign Out"
}
]
}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token=PAGE_ACCESS_TOKEN"
Which SDK are you using, Node or C# ?
C#
@wiltodelta can you elaborate on what you mean by not working? Currently, C# SDK doesn't have support to generate facebook persistent menu. But your bot should be able to receive the payload from the channel like regular message.
For persistent menus you can talk to the facebook API directly. For menus associated with a post you should be able to use the channelData property to send the menu and callbacks should come to you as an activity.
@msft-shahins Is there now a C# SDK Support for facebook persistent menu?
How to create a messenger persistent menu in c# ?
How to create a messenger persistent menu in c# ?
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);
}
}
}
}```