【问题标题】:Bot Framework V3 Email Json objectBot Framework V3 电子邮件 Json 对象
【发布时间】:2018-12-11 22:05:38
【问题描述】:

我正在尝试让机器人回复 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# json azure botframework


    【解决方案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

    【讨论】:

    • 感谢您的回复。这个对话框就够了吗?收件人等呢?文档很吓人,只告诉你 Json 的外观。
    • 收件人将是向机器人发送电子邮件的用户。
    • 您应该使用 MessageReceived 而不是 StartAsync 来发送回复。如果你使用 message.CreateReply();那么 From 和 Recipient 字段将已正确设置。
    • 谢谢。但是 var message = context.Activity as IMessageActivity 来自 StartAsync(IdialogContext context) 没有 CreateReply() 方法。唯一类似的就是 message.CreateOAuthReplyAsync 这似乎不是我需要的方法。
    • ((Activity)context.Activity).CreateReply()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 1970-01-01
    相关资源
    最近更新 更多