简体   繁体   English

从 Bot 框架调用 FB Greeting

[英]Calling FB Greeting from Bot Framework

I was trying to create FB Gretting using C# SDK and sending the curl request according to FB documentation here : https://developers.facebook.com/docs/messenger-platform/thread-settings/greeting-text我试图使用 C# SDK 创建 FB Gretting 并根据此处的 FB 文档发送 curl 请求: https : //developers.facebook.com/docs/messenger-platform/thread-settings/greeting-text

However, seems that there is no response from FB.但是,似乎没有来自FB的回应。 Any pointers would be appreciated.任何指针将不胜感激。 Thanks谢谢

public class MessagesController : ApiController
{
    int i = 0;
    /// <summary>
    /// POST: api/Messages
    /// Receive a message from a user and reply to it
    /// </summary>
    public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
    {

        if (activity.Type == ActivityTypes.Message)
        {
            //await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
            await Conversation.SendAsync(activity, () => new Dialogs.TheQnAMakerDialog());
        }
        else
        {                
            HandleSystemMessage(activity);
        }
        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
    }

    private Activity HandleSystemMessage(Activity message)
    {
        if (message.Type == ActivityTypes.DeleteUserData)
        {
            // Implement user deletion here
            // If we handle user deletion, return a real message
        }
        else if (message.Type == ActivityTypes.ConversationUpdate)
        {
            // Handle conversation state changes, like members being added and removed
            // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
            // Not available in all channels
            var callFB=SendFBGreeting();                
        }
        else if (message.Type == ActivityTypes.ContactRelationUpdate)
        {
            // Handle add/remove from contact lists
            // Activity.From + Activity.Action represent what happened
        }
        else if (message.Type == ActivityTypes.Typing)
        {
            // Handle knowing tha the user is typing
        }
        else if (message.Type == ActivityTypes.Ping)
        {
        }

        return null;
    }

    private async Task<HttpResponseMessage> SendFBGreeting()
    {
        var payload = @"{
            ""setting_type"": ""greeting"",
            ""greeting"": {
                ""text"": ""Timeless apparel for the masses.""
            }
        }";
        var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(payload));
        var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");
        using (var client = new HttpClient())
        {
            // Do the actual request and await the response
            var httpResponse = await client.PostAsync("https://graph.facebook.com/v2.6/me/thread_settings?access_token=xxx", httpContent);

            // If the response contains content we want to read it!
            if (httpResponse.Content != null)
            {
                var responseContent = await httpResponse.Content.ReadAsStringAsync();

            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }
    }
}

Facebook does not return a ConversationUpdate event. Facebook 不会返回ConversationUpdate事件。 Try to call SendFBGreeting() elsewhere.尝试在别处调用SendFBGreeting()

Keep in mind greeting text will be shown before the user Get Started , So even if you do get ConversationUpdate event, it won't matter in this case.请记住,问候文本将在用户开始之前显示,因此即使您确实获得了 ConversationUpdate 事件,在这种情况下也无关紧要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有 v4 网络聊天频道的 Bot Framework 问候语 - Bot Framework Greeting message with v4 Webchat Channel 加载Webchat控件后立即从机器人发送问候语/欢迎语 - Sending a greeting/welcome message from the bot as soon as the Webchat control is loaded 从Azure Bot调用WebAPI - Calling a WebAPI from an Azure Bot 在机器人框架中调用 CancelAllDialogsAsync 时如何传递结果? - How to pass a result when calling CancelAllDialogsAsync in bot framework? Bot Framework 在对话框之间再次调用对象的构造函数 - Bot Framework is calling constructor of object again between dialogs 从javascript调用任何FB API时发生OAuthException 2500 - OAuthException 2500 when calling any FB api from javascript 如何从 Bot Framework 中的数据库中获取 Bot Activity Message? - How to bring the Bot Activity Message from database in Bot Framework? Bot应用程序无法使用其他用户角色(Microsoft Bot Framework) - Bot app not working from another User Role (Microsoft Bot Framework) Bot Framework在Skype上调用Bot:拨号盘在哪里响应数字输入? - Bot Framework Calling Bot on Skype: where is the dial pad to respond to number input? 从 SmtpClient 获取 SMTP 服务器问候消息 - Get SMTP server greeting message from SmtpClient
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM