c# - Bot Framework V3 电子邮件 Json 对象
问题描述
我正在尝试让机器人回复 Bot Framework V3 中的电子邮件。但是我很难理解如何从对话框中调用对象,甚至如何创建 JSON 对象。这些示例已被微软删除,因此几乎没有关于如何执行此操作的示例或文档。有没有人有一个对话框回复我可以使用的电子邮件的例子?
提前致谢。
这是我当前的代码,但它不起作用:
对话:感谢您的回复。这个对话框就够了吗?收件人等呢?文档非常吓人,只告诉你 Json 的外观。
这是我的代码:
消息控制器:
else if (activity.ChannelId == "email")
{
await Conversation.SendAsync(activity, () => new EmailDialogDante());
}
对话:
public async Task StartAsync(IDialogContext context)
{
var message = context.Activity as IMessageActivity;
var reply = context.MakeMessage();
reply.ChannelData = new BotchannelData();
{
ChannelData channelData = new ChannelData();
ChannelDataInter channelDataInter = new ChannelDataInter();
}
await context.PostAsync(reply);
// await fetchOrderDetails(context, query);
}
这些是我的 Json 对象:
public class BotchannelData
{
[JsonProperty("channelData")]
public ChannelData ChannelData
{
get;
internal set;
}
}
}
namespace SimpleEchoBot.EmailJson
{
public class ChannelData
{
public ChannelData()
{
this.Type = "message";
this.Locale = "en-Us";
this.ChannelID = "email";
}
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("locale")]
public dynamic Locale { get; set; }
[JsonProperty("channelID")]
public dynamic ChannelID { get; set; }
[JsonProperty("from")]
public From From { get; internal set; }
[JsonProperty("recipient")]
public Recipient Recipient { get; internal set; }
[JsonProperty("conversation")]
public Conversation Conversation { get; internal set; }
[JsonProperty("channelData")]
public ChannelDataInter ChannelDataInter { get; internal set; }
}
}
namespace SimpleEchoBot.EmailJson
{
public class ChannelDataInter
{
public ChannelDataInter()
{
this.HTML = "test";
this.Subject = "testing";
this.Importance = "high";
}
[JsonProperty("html")]
public string HTML { get; set; }
[JsonProperty("subject")]
public dynamic Subject { get; set; }
[JsonProperty("importance")]
public dynamic Importance { get; set; }
}
}
解决方案
可以使用以下方式在ChannelData中设置电子邮件通道特定属性:
if (message.ChannelId == ChannelIds.Email)
{
var reply = message.CreateReply();
reply.ChannelData = JObject.FromObject(new
{
htmlBody = "<html><body style=\"font-family: Calibri; font-size: 11pt;\">This is the email body!</body></html>",
subject = "This is the email subject",
importance = "high"
});
//send reply to user
await context.PostAsync(reply);
}
对相关文档的一些参考:
推荐阅读
- python - Flask/Python - 如何使用来自多个 IP 摄像机的实时镜头填充 HTML 页面?
- opentok - OpenTok 按钮来控制视频
- java - 带有参数和单引号的自定义 HQL 函数
- python - 检查两个字符串之间的顺序是否保持不变
- entity-framework - 如何解析实体框架中的特殊字符?
- python-3.x - AWS Lambda 中的 lxml 库
- python-3.x - 为什么我的递归函数没有连接字符串?
- react-native - iOS 上的 React Native:图像组件未从特定 URI 渲染图像
- javascript - 交换 Divs 然后在两个选择列表之间交换选定的选项值
- sql - 在 SQL Server 的视图创建脚本中使用变量