gpt4 book ai didi

c# - [机器人框架] : How to fix:Welcome message is not getting displayed to the user in C# WebChatBot developed in V4 but displayed in Emulator?

转载 作者:行者123 更新时间:2023-12-05 00:58:51 24 4
gpt4 key购买 nike

<!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# 中创建了聊天机器人,当用户在浏览器中打开网络聊天机器人时,我试图显示欢迎文本。目前,欢迎文本在模拟器中显示,但在 WebchatBot 发布到 Azure 后打开的 ion 浏览器中不显示。只有在我输入诸如“嗨”之类的东西后,它才会显示欢迎消息。这不应该是这样,它应该首先显示欢迎文本,然后我可以输入 Hi 或其他任何内容来继续对话

问题:欢迎消息显示在模拟器中,但在发布后不显示在网络聊天机器人中,仅在我输入任何内容后才显示?在浏览器中打开 Webchatbot 后应立即显示欢迎消息。

语言:C#

机器人 SDK:V4

Bot Builder 包:通过 Nuget 更新到 4.4.3

Bot Emulator:从 GitHub 版本下载并安装的最新 4.4.1

欢迎文本在 IBOT 类的 OnTurnSync 方法内的 ConversationUpdate 事件中调用。下面给出的代码供引用。

由于我是 BOT 和编码新手,请提供分步指导来帮助我吗?

我已经尝试了一些类似的方法:

  1. 在模拟器中调试但没有太大帮助

下面的代码我用过:

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 中显示。
实际结果:欢迎文字仅在模拟器中有效,在 Webchatbot 中无效,仅在我输入任何内容后才会显示。

最佳答案

这是一个关于欢迎用户的常见问题。

每个 channel 的 channel 抛出的事件并不相同:WebchatEmulator 中的事件之间的主要区别之一是:

  • 在模拟器上, session 开始时会发送 2 个 ConversationUpdate 事件(添加 1 个 Bot,添加 1 个 User)
  • 在网络聊天中,关于用户的 ConversationUpdate 仅在用户发送 1 条消息后发送

因此,要绕过这种行为,您可以使用称为 backchannel 的机制来处理您身边的 event。在 Github 的存储库 here 上有此用例的示例

简而言之,您必须:

  • 在开始时通过网络聊天发送事件
  • 在机器人端处理此事件并处理您的欢迎消息

关于c# - [机器人框架] : How to fix:Welcome message is not getting displayed to the user in C# WebChatBot developed in V4 but displayed in Emulator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56111293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com