botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Facebook menu

Open wiltodelta opened this issue 10 years ago • 8 comments

Facebook menu doesn't work for me.

screen shot 2016-10-10 at 07 22 32
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"

wiltodelta avatar Oct 10 '16 04:10 wiltodelta

Which SDK are you using, Node or C# ?

danmarshall avatar Oct 12 '16 01:10 danmarshall

C#

wiltodelta avatar Oct 28 '16 07:10 wiltodelta

@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.

msft-shahins avatar Oct 28 '16 18:10 msft-shahins

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.

tomlm avatar Nov 04 '16 00:11 tomlm

@msft-shahins Is there now a C# SDK Support for facebook persistent menu?

kevinport avatar Mar 07 '17 13:03 kevinport

How to create a messenger persistent menu in c# ?

Raziellzz avatar Mar 27 '17 11:03 Raziellzz

How to create a messenger persistent menu in c# ?

krconnect avatar Jun 05 '17 18:06 krconnect

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);
        } 
    }
}
}```

krconnect avatar Jul 17 '17 14:07 krconnect