<!DOCTYPE html>
<html>
<head>
<title>Avanade D365 F&O Assets BOT</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--
For demonstration purposes, we are using development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
Or locked down on a specific version "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<style>
html, body {
height: 100%
}
body {
margin: 0
}
#webchat {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="webchat" role="main">
<iframe src='https://webchat.botframework.com/embed/AssetsBot?s=<<given my code here as it is secret i have attached this removing the code>>' style='min-width: 400px; width: 100%; min-height: 500px;'></iframe>
</div>
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<script>
// We are using a customized store to add hooks to connect event
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
// When we receive DIRECT_LINE/CONNECT_FULFILLED action, we will send an event activity using WEB_CHAT/SEND_EVENT
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: { language: window.navigator.language }
}
});
}
return next(action);
});
const styleOptions = {
botAvatarImage: '<<Given Image URL, removed as these are project specific>>',
botAvatarInitials: 'BF',
userAvatarImage: '<<Given Image URL, removed as these are project specific>>',
userAvatarInitials: 'WC',
bubbleBackground: 'rgba(0, 0, 255, .1)',
bubbleFromUserBackground: 'rgba(0, 255, 0, .1)'
};
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ secret: '<<given my code here as it is secret i have attached this removing the code>>' }),
// Passing "styleOptions" when rendering Web Chat
styleOptions
}, document.getElementById('webchat'));
</script>
</body>
</html>
我使用 SDK 4 在 C# 中创建了聊天机器人,当用户在浏览器中打开网络聊天机器人时,我尝试显示欢迎文本。
目前,欢迎文本显示在模拟器中,但在发布到 Azure 后打开的 WebchatBot 离子浏览器中不显示。
仅在我输入“嗨”或其他内容后,它才显示欢迎消息。情况不应该是这样,它应该首先显示欢迎文本,然后我可以输入 Hi 或其他任何内容来继续对话
问题:发布后,欢迎消息显示在模拟器中,但不显示在网络聊天机器人中,仅在我输入任何内容后才显示?在浏览器中打开 Webchatbot 后应立即显示欢迎消息。
语言:C#
机器人 SDK:V4
Bot Builder 软件包:全部通过 Nuget 更新至 4.4.3
Bot Emulator:从 GitHub 版本下载并安装最新的 4.4.1
欢迎文本在 IBOT 类的 OnTurnSync 方法内的 ConversationUpdate 活动中调用。下面给出代码供参考。
由于我是 BOT 和编码的新手,请提供逐步指导来帮助我?
我已经尝试过一些事情,例如:
- 在模拟器中调试
但没有多大帮助
我使用过以下代码:
public const string WelcomeText = "Welcome!. This bot uses a custom dialog that executes a data driven flow. Type anything to get started.";
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate)
{
if (turnContext.Activity.MembersAdded != null)
{
await SendWelcomeMessageAsync(turnContext, cancellationToken);
}
}
}
private static async Task SendWelcomeMessageAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
foreach (var member in turnContext.Activity.MembersAdded)
{
if (member.Id != turnContext.Activity.Recipient.Id)
{
var reply = turnContext.Activity.CreateReply();
reply.Text = WelcomeText;
await turnContext.SendActivityAsync(reply, cancellationToken);
}
}
}
预期结果:欢迎文本不仅在模拟器中发布,还应在发布后显示在 WebchatBot 中。
实际结果:欢迎文本仅在模拟器中有效,但在网络聊天机器人中无效,只有在我输入任何内容后才会显示。