我有一个基于BotFramework 3.5的机器人,并作为WebApp托管在Azure上.我没有遇到机器人需要响应用户输入的情况的实施问题.但是,有必要教他按一些时间表开始对话.为了达到目标,我创建了一个WebJob,它基本上是一个简单的控制台应用程序.以下是用于启动从bot到用户的消息的代码:
var botAccount = new ChannelAccount(id: from);
var userAccount = new ChannelAccount(id: to);
var conversation = new ConversationAccount(false, conversationId);
var connector = new ConnectorClient(serviceUrl);
IMessageActivity message = Activity.CreateMessageActivity();
message.From = botAccount;
message.Recipient = userAccount;
message.Conversation = conversation;
message.Text = text;
message.Locale = locale;
await connector.Conversations.SendToConversationAsync((Activity)message);
Run Code Online (Sandbox Code Playgroud)
from, to, serviceUrl, conversationId - 取自之前的对话,所以我希望它们有效.但是SendToConversationAsync 抛出异常:
System.UnauthorizedAccessException: Authorization for Microsoft App ID 3a26a4d4-f75a-4feb-b3e0-37a7fa24e5fc failed with status code Unauthorized and reason phrase 'Unauthorized' ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 …Run Code Online (Sandbox Code Playgroud) FormBuilder当我在路易斯创建时,我正试图结合我的意图.我只是找不到这样做的文档.
我想做以下事情:
我该怎么做呢?有教程吗?我看到人们在谈论LuisDialogs,但我只是不知道从哪里开始.
所以现在我正在使用Microsoft.Bot.Builder.Dialogs.Conversation.SendAsync并Microsoft.Bot.Builder.Dialogs.Conversation.ResumeAsync实现一种暂停和恢复对话的方法,但似乎无法"退出"或回到之前的状态.它停留在对话对话框中.
我只是实现'取消'命令吗?如果是这样,我需要清除哪些数据才能恢复到原始状态?
public static readonly IDialog<string> dialog = Chain
.PostToChain()
.Switch(
new Case<Message, IDialog<string>>((msg) =>
{
var regex = new Regex("login", RegexOptions.IgnoreCase);
return regex.IsMatch(msg.Text);
}, (ctx, msg) =>
{
return Chain.ContinueWith(new ChatDialog(msg),
async (context, res) =>
{
var token = await res;
//var valid = await Helpers.ValidateAccessToken(token);
//var name = await Helpers.GetProfileName(token);
var name = "User";
context.UserData.SetValue("name", name);
return Chain.Return($"You are logged in as: {name}");
});
})
).Unwrap().PostToUser();
Run Code Online (Sandbox Code Playgroud)
因此,如果我发送"登录",它将会开始一个新的ChatDialog对话,但它似乎陷入了这种状态.即使我尝试发送另一个命令,它也会继续要求登录.我是否实现了另一个Case类来处理"取消"命令?或者,当用户多次发送相同的"登录"命令时,它是否应自动取消对话?看起来有点笨重,必须单独发送'取消'命令.
我不确定如何处理丰富的内容.我想要返回的一些示例是超链接列表或/某些图像缩略图.我该怎么做呢?我尝试将我的文本格式化为HTML并且崩溃了Bot Emulator并导致Web Chat客户端只显示编码的HTML.
这个或一些文件解释这个有秘密吗?
我试图从标记为一个方法中获得完整的原始文本LuisIntent中的LuisDialog.
文档将这些方法显示为两个参数:
IDialogContext context, LuisResult result
Run Code Online (Sandbox Code Playgroud)
这两者都没有公开披露消息的原始文本.上下文对象确实包含消息但在私有属性(context.data.message.text)中是不可访问的.
有没有办法在中访问它context,还是可以将它传递给对话框构造函数?
在 Bot Emulator 中从 Azure 测试 EchoBot 模板时,我不断收到“无法发布活动。未经授权”。我该如何防范?我是 .NET 的新手,所以不明白这里的身份验证是如何工作的。我可以看到正在加载的配置设置,但我看不到它们是如何在 Azure 的默认 EchoBot 模板中提供或应用的。
我发现如果我在 appsettings.json 中定义了“MicrosoftAppID”和“MicrosoftAppPassword”,我只会获得未授权。如果我将这些注释掉,它就可以正常工作。
[HttpPost]
public async Task PostAsync()
{
// Delegate the processing of the HTTP POST to the adapter.
// The adapter will invoke the bot.
await Adapter.ProcessAsync(Request, Response, Bot);
}
Run Code Online (Sandbox Code Playgroud)
所以我想了解如何避免在本地测试代码时必须注释掉这些行。PostAsync 返回 401。
我是Microsoft Bot框架的新手.现在我正在模拟器上测试我的代码.我想在你连接后立即发送Hello消息.以下是我的代码.
var restify = require('restify');
var builder = require('botbuilder');
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
var connector = new builder.ChatConnector({
appId: "-- APP ID --",
appPassword: "-- APP PASS --"
});
var bot = new builder.UniversalBot(connector);
server.post('/api/message/',connector.listen());
bot.dialog('/', function (session) {
session.send("Hello");
session.beginDialog('/createSubscription');
});
Run Code Online (Sandbox Code Playgroud)
上面的代码在用户发起对话时发送Hello消息.我想在用户连接后立即发送此消息.
有简单的函数返回错误:
错误:date.toLocaleDateString不是函数
TypeError: date.toLocaleDateString is not a function
at FormatTime (../Src/rootdialog.js:87:58)
Run Code Online (Sandbox Code Playgroud)
功能定义:
function FormatTime(time, prefix = "") {
var date = Date.parse(time);
return ((typeof time != "undefined") ? prefix + date.toLocaleDateString() : "");
}
Run Code Online (Sandbox Code Playgroud)
函数接收Date对象作为输入,但即使显式转换为Datewith Date.parse()也无济于事.使用Node.js 8.x. 有解决方案吗
PS问题是由BotBuilder架构引起的.
情况1我编写了自己的bot框架并部署到Azure,Web Chat中的测试向我展示了"在部署后等待机器人准备就绪".
情况2我从Azure bot服务下载了源代码,之后我部署回Azure,Web Chat向我展示了"等待部署后机器人准备就绪".
botframework ×10
c# ×4
azure-language-understanding ×2
bots ×2
node.js ×2
.net ×1
azure ×1
date ×1
javascript ×1
string ×1