我正在使用C#中的Microsoft Bot Framework V3构建一个机器人,并尝试让Dialog启动并在用户输入任何输入之前“欢迎”用户。我还希望每次用户填写表单时都重复使用Dialog。
我正在尝试使用FormFlow选项:FormOptions.PromptInStart但它仍然只有在输入一些输入后才会显示欢迎消息。不确定这是否已被弃用,或者我只是做得不对。有什么建议??
我的课程如下:
MessagesController:
internal static IDialog<MyClass> MakeRootDialog()
{
return Chain.From(() => FormDialog.FromForm(MyClass.BuildForm, options: FormOptions.PromptInStart))
.Do(async (context, order) =>
{//some actions here }
});
}
MyClass.cs:
[Serializable]
public class MyClassDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
}
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
var message = await argument;
await context.PostAsync("You said: " + message.Text);
context.Wait(MessageReceivedAsync);
}
}
MyClassDialog.cs:
public class MyClass
{
public static IForm<MyClass> BuildForm()
{
OnCompletionAsyncDelegate<MyClass> processOrder = async (context, state) =>
{
await context.PostAsync("We are currently filing your order.....");
};
return new FormBuilder<MyClass>()
.Message("Welcome to my bot!")
//some actions here
.Confirm(//more actions here)
.AddRemainingFields()
.Message("Thanks for providing your inputs")
.OnCompletion(processOrder)
.Build();
}
};
答案 0 :(得分:1)
如何实现Post方法? 我认为你在形式方面没有问题,但在Post方法中。
此代码适用于我。
public async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
if (activity.Type == ActivityTypes.Message || activity.Type == ActivityTypes.ConversationUpdate)
{
Conversation.SendAsync(activity, MakeRootDialog);
{
}
因为如果用户连接,ActivityType是ConversationUpdate,没有消息。当activity.Type == ActivityTypes.ConversationUpdate时,你必须调用MakeRootDialog。
答案 1 :(得分:1)
你可以检查message.Type == ActivityTypes.ConversationUpdate和message.MembersAdded.Any(o =&gt; o.Id == message.Recipient.Id)
ref from BotBuilder-Samples/CSharp/demo-ContosoFlowers/
RewriteEngine On
RewriteBase /
# allow these referers to passthrough
RewriteCond %{HTTP_REFERER} !^http://localhost/allow [NC]
RewriteRule ^ https://google.com/ [R,L]
答案 2 :(得分:0)
我有类似的经历,似乎取决于客户。我在本地模拟器中获得了相同的体验,但是当我通过网络聊天客户端运行时,我看到了欢迎信息:https://docs.botframework.com/en-us/support/embed-chat-control2/
我在网聊中添加了一个screendump:Welcome message in webchat