首页 > 解决方案 > 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; }
}
}

标签: c#jsonazurebotframework

解决方案


可以使用以下方式在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);
}

对相关文档的一些参考:

自定义电子邮件

创建自定义电子邮件


推荐阅读