是否可以从azure bot v4打开widgets.getsitecontrol.com/javascript?

问题描述 投票:0回答:1

我想打开我在网站上实现的widgets.getsitecontrol.com/ javascript页面。每当我在我的机器人中输入“帮助”时,小部件就应该打开。有可能打开它吗?谢谢。我正在使用node js版本。如果有可能,请为我提供解决此问题的方法。

node.js azure widget botframework
1个回答
0
投票

我不确定您的小部件是如何运作的,但是当用户向机器人发送“帮助”消息时,您可以向WebChat发送反向通道事件以触发打开小部件。看一下下面的代码片段。

Bot代码 - NodeJs

当机器人从用户收到“帮助”消息时,机器人可以通过发送类型设置为“事件”的活动来发送事件。我们还可以为传出活动提供名称属性,以便我们可以向WebChat发送多种类型的事件。在这种情况下,我们将命名即将开展的活动'helpEvent'。

async onTurn(turnContext) {
    if(turnContext.activity.type === ActivityTypes.Message) {
        if (turnContext.activity.text.toLowerCase() === 'help') {
            // Send Back Channel Help Event
            await turnContext.sendActivity({ type: 'event', name: 'helpEvent'});
        }
    ...
    }
}

WebChat自定义中间件

在WebChat中,我们将创建一个自定义中间件来检查传入的活动。当我们遇到具有我们识别的名称和类型的活动时,请在网页上触发您的活动。在下面的示例中,我刚刚提醒他们请求帮助,但这里是您启动窗口小部件的地方。

const store = window.WebChat.createStore(
    {},
    ({ dispatch }) => next => action => {
        if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
          const { name, type } = action.payload.activity;

          if (type === 'event' && name === 'helpEvent') {
            // Activate Widget 
            alert("You asked for help.");
          }
        }
        return next(action);
    }
);

window.WebChat.renderWebChat({
    directLine: window.WebChat.createDirectLine({ token }),
    store,
}, document.getElementById('webchat'));

有关反向通道事件和在WebChat中创建自定义中间件的更多详细信息,请在WebChat Repo中查看this sample

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.