本文介绍了使用 C# 在 AutoPilot 中返回 Json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经翻阅了文档并阅读了相关帖子,但我仍然无法为包含多个元素的 Action 数组成功构建 Json.

I have poured over the documentation and read the related posts but I am still unable to successfully construct the Json for an Action array containing multiple elements.

第一个元素是一个记住"动作,包含它自己的几个元素.第二个 Action 元素是收集"操作.

The first element is a "Remember" action containing several elements of its own. The second Action element is a "Collect" action.

我可以添加第一个元素,但第二个元素无法添加.我发布的代码包含错误.我无法添加第二个收集"元素.我是关闭还是远离?非常感谢任何指导.

I am able to add the first element but the second element eludes me. The code I am posting contains errors. I am unable to add the second "Collect" element. Am I close or way off? Any guidance is greatly appreciated.

[HttpPost]
[Route("AcceptTask")]
internal string BuildAcceptCall(UserData ud)
{
    log.Debug("Entering BuildAcceptCall");
    var j = new
    {
        actions = new[]
        {
            new
           {
                remember = new
                   {
                         ud.AccountId,
                        EngineId = ud.EngineId,
                        ResidentTelephone = ud.ResidentTelephone,
                        OutboundCallerId = ud.OutboundCallerId,
                        UnitNumber = ud.UnitNumber,
                        BuildingNumber = ud.BuildingNumber,
                        Pets = ud.Pets,
                        Alarm = ud.Alarm,
                        EmergencyId = ud.EmergencyId,
                        CallDate = ud.CallDate,
                        WorkOrder = ud.WorkOrder,
                        CurrentLocation = ud.CurrentLocation
                   }, //close remember element

               collect = new
                {
                    name = "DidTechAcceptCall",
                    questions = new[]
                    {
                       new
                           {
                               question = "This is a maintenance call from Spring Meadows. will you accept the call?",
                               name = "OffferCallToTech",
                               type="Twilio.YES_NO"
                            }
                    },
                    on_complete = new
                    {
                        redirect = new
                        {
                            uri = @"https://8.40.212.131/MedsDispatch/api/Dispatch/EntryPoint_AutoPilot",
                            method = "post"
                        }
                    }
               }//close the collect element
            } //close the new
        }; //close the array

    string theObject = Newtonsoft.Json.JsonConvert.SerializeObject(j); ;
    return Newtonsoft.Json.JsonConvert.SerializeObject(j);

}

推荐答案

我强烈建议您执行以下一项或全部操作

I highly recommend that you do one or all of the following

  • 使用 Twilio SDK for C# 和 .NETDocs 用于创建Task在 C# 中.
  • 任何类型的静态任务都可以通过 Twilio 的 AutoPilot 控制台轻松构建
  • Use Twilio SDK for C# and .NET and Docs for creating a Task in C#.
  • Any kind of static task can be easily built off Twilio's AutoPilot Console

无论如何,这是代码

var j = new { actions = new object[]{
                new{
                    remember = new{
                        data = "data"
                    }
                },
                new{
                    collect = new{
                        name = "DidTechAcceptCall",
                        questions = new[]
                        {
                           new
                               {
                                   question = "This is a maintenance call from Spring Meadows. will you accept the call?",
                                   name = "OffferCallToTech",
                                   type="Twilio.YES_NO"
                                }
                        },
                        on_complete = new
                        {
                            redirect = new
                            {
                                uri = @"https://8.40.212.131/MedsDispatch/api/Dispatch/EntryPoint_AutoPilot",
                                method = "post"
                            }
                        }
                    }
                }
     }
};
string theObject = Newtonsoft.Json.JsonConvert.SerializeObject(j);
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(j));

产生

{
  "actions": [
    {
        "remember": {
            "data": "data"
        }
    },
    {
        "collect": {
            "name": "DidTechAcceptCall",
            "questions": [
                {
                    "question": "This is a maintenance call from Spring Meadows. will you accept the call?",
                    "name": "OffferCallToTech",
                    "type": "Twilio.YES_NO"
                }
            ],
            "on_complete": {
                "redirect": {
                    "uri": "https://8.40.212.131/MedsDispatch/api/Dispatch/EntryPoint_AutoPilot",
                    "method": "post"
                }
            }
        }
    }
  ]
}

这篇关于使用 C# 在 AutoPilot 中返回 Json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 16:59