【发布时间】:2016-10-20 08:12:49
【问题描述】:
我首先通过 OAuthCallback 方法中的短信通道向用户发送主动消息
var connector = new ConnectorClient();
Message message = new Message();
message.From = new ChannelAccount { Id = Constants.botId, Address = "+12312311", ChannelId = "sms", IsBot = true };
message.To = new ChannelAccount { Id = newUserId, Address = "+18768763", ChannelId = "sms", IsBot = false };
message.Text = $"How are you doing? ";
message.Language = "en";
connector.Messages.SendMessage(message);
IBotData myDataBag = new JObjectBotData(message);
myDataBag.UserData.SetValue("Username", "Bob");
myDataBag.PerUserInConversationData.SetValue("Newuser", "yes");
然后在我的主 Dialog.cs 中尝试访问它
public static readonly IDialog<string> dialog = Chain
.PostToChain()
.Switch(new Case<Message, IDialog<string>>((msg) =>
{
var regex = new Regex("hello$", RegexOptions.IgnoreCase);
return regex.IsMatch(msg.Text);
},
(ctx, msg) =>
{
// Clearing user related data upon logout
string isnewuser = ctx.PerUserInConversationData.TryGetValue("Newuser");
string username = ctx.UserData.TryGetValue("Username");
return Chain.Return($"Welcome {username}");
}))
.Unwrap()
.PostToUser();
我在手机上收到消息。但是,我无法取回保存在 OAuthCallback 中的用户名和 newuser 会话数据。
我怀疑这是因为主动消息没有设置 conversationId。而且conversationId 必须有所不同。
那么我怎样才能让它在未来的对话中将会话数据设置为我的主动消息?
【问题讨论】:
-
不是解决方案,但是如果我没记错的话,在发送主动消息时不需要设置conversationId。框架将检查是否存在。如果 conversationId 存在,它会将该消息发送到该对话,如果不存在,则开始一个新对话。 source 另外,您是通过模拟器执行此操作,还是在 Azure 中有您的机器人?我正在尝试通过模拟器发送主动消息并收到 500 状态代码。
-
@pl0x 它在模拟器中不起作用。我更想知道如何在由主动消息启动的 convo 上设置会话数据,这在这种情况下似乎不起作用。
-
一旦我在 Azure 上安装了我的机器人,如果我知道如何设置会话数据,我会通知你。
-
我们现在有一个sample 用于创建新对话。
-
我做过一次,看这里github.com/DanielHWe/NotifyBot
标签: c# botframework