如何在 Directline 语音网络聊天中 'DIRECT_LINE/CONNECT_FULFILLED' 时添加 activity
How to add an activity when 'DIRECT_LINE/CONNECT_FULFILLED' in Directline Speech webchat
我试过了example for sending an activity to bot when the connection is established, Its working fine. Now I want use Directline speech instead of webchat, It also has a sample here。但是在这里我该如何添加欢迎活动呢?这是我试过的代码,但它没有发送任何 activity
<script>
(async function () {
const adapters = await window.WebChat.createDirectLineSpeechAdapters({
fetchCredentials: {
region: 'region',
subscriptionKey: 'my subscription key'
}
}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: 'my username'
}
});
}
return next(action);
});
window.WebChat.renderWebChat(
{
...adapters
},
document.getElementById('webchat')
);
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
我通过添加商店来实现它,这是代码
<script>
(async function () {
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: 'my username'
}
});
}
return next(action);
});
const adapters = await window.WebChat.createDirectLineSpeechAdapters({
fetchCredentials: {
region: 'region',
subscriptionKey: 'subscription key'
}
});
window.WebChat.renderWebChat(
{
...adapters, store
},
document.getElementById('webchat')
);
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
我试过了example for sending an activity to bot when the connection is established, Its working fine. Now I want use Directline speech instead of webchat, It also has a sample here。但是在这里我该如何添加欢迎活动呢?这是我试过的代码,但它没有发送任何 activity
<script>
(async function () {
const adapters = await window.WebChat.createDirectLineSpeechAdapters({
fetchCredentials: {
region: 'region',
subscriptionKey: 'my subscription key'
}
}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: 'my username'
}
});
}
return next(action);
});
window.WebChat.renderWebChat(
{
...adapters
},
document.getElementById('webchat')
);
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
我通过添加商店来实现它,这是代码
<script>
(async function () {
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: 'my username'
}
});
}
return next(action);
});
const adapters = await window.WebChat.createDirectLineSpeechAdapters({
fetchCredentials: {
region: 'region',
subscriptionKey: 'subscription key'
}
});
window.WebChat.renderWebChat(
{
...adapters, store
},
document.getElementById('webchat')
);
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>