0

我正在使用直线进行网络聊天。

我想在聊天顶部包含一个刷新按钮,为此我需要对话 ID。我怎样才能得到身份证?是否可以使用内联网络聊天? 这是我试图实现的刷新按钮

4

1 回答 1

3

我遇到了同样的问题,因为我想将对话 ID 传递给我的自定义控制器以进行初始身份验证,并相应地将自定义身份验证数据推送到与该特定对话 ID 相关的机器人框架的对话堆栈。

我的狩猎让我在 Github 上发表了这个问题:

inmarktech的第三篇文章中,他提到了以下代码:

var params = BotChat.queryParams(location.search);
var my_token = params['my_token'];

var botConnection = new BotChat.DirectLine({
    secret: 'DIRECTLINE_SECRET'
});

BotChat.App({
    botConnection: botConnection
    ,user: { id: 'USER_ID', name: 'User' }  // user.id auto updates after first user message
}, document.getElementById("bot"));

botConnection.connectionStatus$.subscribe(function (status) {
    if (status == 2) {  // wait for connection is 'OnLine' to send data to bot
        var convID = botConnection.conversationId;
        botConnection.postActivity({
            from: { id: convID }  // because first time user ID == conversation ID
            ,type: 'event'
            ,name: 'registerUserData'    // event name as we need
            ,value: my_token   // data attached to event
        }).subscribe(function (activityId) {
            // This subscription is a MUST
            // If I remove this handler the postActivity not reaches the bot
        });
    }
});

如您所见,他正在订阅botConnection.connectionStatus$并且当状态属性等于 2(Online) 时,您可以从 botConnection 对象获取对话 ID。

希望有帮助:)

于 2018-04-26T10:23:28.057 回答