关于如何从与会者和漫游器之间的对话中获取此ID的任何想法吗? [英] Any idea on how to get this id from the conversation between attendee and bot?

查看:80
本文介绍了关于如何从与会者和漫游器之间的对话中获取此ID的任何想法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:

BotFramework(C#SDK)+ Messenger频道,该机器人处理两种类型的用户:参与者(Messenger用户)和组织者(Facebook Page的管理员).

BotFramework (C# SDK) + Messenger channel, bot handles two types of users: attendees (Messenger users) and organizers (who are Facebook Page's admins).

用例:

当与会者请求人员支持(使用我的机器人菜单中的选项)时,组织者将收到一条消息.

When an attendee requests a human support (using an option in my bot's menu), the organizer will receive a message.

在该消息中,我想添加一个按钮,一旦组织者单击该按钮,它将执行以下操作:

In that message, I would like to add a button that will do the following once clicked by the organizer:

  1. 停止从漫游器向该用户的自动回复
  2. 将组织者重定向到Facebook的Page收件箱,并选择对话(在参与者和漫游器之间)

我所做的事情:

  • 我成功完成了阻止自动回复的部分

  • I successfully did the part to stop the automatic replies

我在如何将组织者重定向到FB Page的收件箱中的正确对话上陷入困境

I got stuck on how to redirect the organizer to the right conversation in FB Page's inbox

技术上:

当我在Facebook Page中查看时,似乎应该为我的操作生成的链接如下:https://www.facebook.com/mypage-mypageId/inbox/?selected_item_id=someId

When I'm looking in Facebook Page, the link that seems to be the one that I should generate for my action is like the following: https://www.facebook.com/mypage-mypageId/inbox/?selected_item_id=someId

我的问题是我在机器人的对话中找不到selected_item_id的值.

My problem is that I can't find this value for selected_item_id from my bot's conversation.

推荐答案

借助Facebook Graph API,您将能够获得到Facebook页面收件箱的链接(具有正确的线程).

You will be able to get a link to the facebook page inbox (with the right thread) thanks to Facebook Graph API.

/me/conversations来获取页面的对话(因此您必须将页面的access_token赋予API调用).

/me/conversations must be called to get the conversations of the Page (so you have to give an access_token of the page to the API call).

然后在这些结果中,您必须与与会者的对话进行匹配.为此,您可以在漫游器中使用活动的属性id (Activity.Id,而不是Activity.Conversation.Id!),因为该值在漫游器和Facebook图形结果之间是通用的(只需要添加"m_"进行匹配即可):您可以在Graph API结果的一个message.id中找到它(小心:不要对话.id)

Then in those results, you have to make a match with the conversation of the attendee. To do this, you can use the property id of the Activity in your bot (Activity.Id, not Activity.Conversation.Id!) as this value is common between your bot and facebook graph results (just need to add "m_" to match): you can find it in one message.id on your Graph API results (careful: not conversation.id)

然后,您可以为您发现的此次对话获取Graph API结果的link值:在我的测试中为"link": "\/myBotName\/manager\/messages\/?threadid=10154736814928655&folder=inbox"

Then you can get the link value of the Graph API result for this conversation that you found: "link": "\/myBotName\/manager\/messages\/?threadid=10154736814928655&folder=inbox" in my test

以下是对话框的示例,该对话框将在链接中搜索特定的消息ID:

Here is a sample of a Dialog that will search for the link for a specific message id:

[Serializable]
public class FacebookGetLinkTestDialog : IDialog<string>
{
    public async Task StartAsync(IDialogContext context)
    {
        context.Wait(MessageReceivedAsync);
    }

    public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
    {
        var jsonString = "";
        var link = "";

        using (var client = new HttpClient())
        {
            using (var response = await client.GetAsync($"https://graph.facebook.com/v2.9/me/conversations?access_token=yourAccessTokenHere").ConfigureAwait(false))
            {
                jsonString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
                var conversationList = Newtonsoft.Json.JsonConvert.DeserializeObject<ConversationsRootObject>(jsonString);
                link = conversationList.data.Single(c => c.messages.data.Any(d => d.id.Equals("m_" + "yourActivityIdHere"))).link;
            }
        }
        await context.PostAsync($"{link}");
    }
}

public class ConversationsRootObject
{
    public List<Conversation> data { get; set; }
    public Paging paging { get; set; }
}

public class Conversation
{
    public string id { get; set; }
    public string snippet { get; set; }
    public string updated_time { get; set; }
    public int message_count { get; set; }
    public int unread_count { get; set; }
    public Participants participants { get; set; }
    public FormerParticipants former_participants { get; set; }
    public Senders senders { get; set; }
    public Messages messages { get; set; }
    public bool can_reply { get; set; }
    public bool is_subscribed { get; set; }
    public string link { get; set; }
}

public class Participant
{
    public string name { get; set; }
    public string email { get; set; }
    public string id { get; set; }
}

public class Participants
{
    public List<Participant> data { get; set; }
}

public class FormerParticipants
{
    public List<object> data { get; set; }
}

public class Senders
{
    public List<Participant> data { get; set; }
}

public class Messages
{
    public List<FbMessage> data { get; set; }
    public Paging paging { get; set; }
}

public class FbMessage
{
    public string id { get; set; }
    public string created_time { get; set; }
}

public class Cursors
{
    public string before { get; set; }
    public string after { get; set; }
}

public class Paging
{
    public Cursors cursors { get; set; }
    public string next { get; set; }
}

这篇关于关于如何从与会者和漫游器之间的对话中获取此ID的任何想法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆