[英]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.