Bot Framework V3电子邮件Json对象

时间:2018-12-10 19:23:51

标签: c# json azure botframework

我正在尝试使Bot回复Bot Framework V3中的电子邮件。但是,我正在努力了解如何从对话框中调用对象,甚至如何创建JSON对象。 这些示例已被Microsoft删除,因此几乎没有任何示例或有关此操作的文档。 有没有人举一个对话框来回复我可以使用的电子邮件?

谢谢。

这是我当前的代码,但是不起作用:

对话框: 谢谢您的回复。 这个对话框就足够了吗?接收者等呢? 该文档非常令人恐惧,只告诉您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; }
}
}

1 个答案:

答案 0 :(得分:1)

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

对相关文档的一些引用:

Customize emails

Create a custom Email message