使用C#通过PlumVoice IVR创建出站活动

时间:2015-03-19 23:59:57

标签: c# ivr

我一直在使用PlumVoice IVR系统一段时间,现在需要利用他们的出站呼叫功能。我需要在C#中执行此操作,但由于缺乏记录的C#支持,我很难弄清楚如何继续。以下是我的项目的具体内容:

  • 我从文件中解析数据(例如电话号码),然后用文件'来调用[那些]号码。数据。
  • 不是 MVC项目(你可以看看它是如何变得更容易)

现在我需要:

  1. 使用queuecall网络服务
  2. 创建一个[广告系列]
  3. 创建 报告后处理的报告功能

1 个答案:

答案 0 :(得分:0)

我已经为我的项目编译和测试了必要的代码,它完全符合要求(直到客户更新要求,显然)。


WebRequest方法

public static void PlumOutboundQueuecall(ObjectModel model)
{
    // Create a request for the URL.        
    WebRequest request = WebRequest.Create(Settings.IvrOutboundApi); //ease of editing/reusability //http://outbound.plumvoice.com/webservice/queuecall.php
    request.Method = "POST";
    //request.ContentType = "multipart/form-data"; //This is only if I choose to upload a [.csv] file of phone numbers
    request.ContentType = "application/x-www-form-urlencoded";

    // I used http://stackoverflow.com/questions/14702902/post-form-data-using-httpwebrequest as reference for proper encoding
    StringBuilder postData = new StringBuilder();
    postData.Append(HttpUtility.UrlEncode("login") + "=" +              HttpUtility.UrlEncode("<MY_EMAIL_FOR_PLUM>") + "&");
    postData.Append(HttpUtility.UrlEncode("pin") + "=" +                HttpUtility.UrlEncode("<MY_PIN_FOR_PLUM>") + "&");
    postData.Append(HttpUtility.UrlEncode("phone_number") + "=" +       HttpUtility.UrlEncode(model.PhoneNumber) + "&");
    postData.Append(HttpUtility.UrlEncode("start_url") + "=" +          HttpUtility.UrlEncode("<MY_vXML_AS_ASPX_PAGE_SHOWN_BELOW>") + "&"); //"http://ip_address/MY_ASPX_PAGE.aspx"
    postData.Append(HttpUtility.UrlEncode("call_parameters") + "=" +    HttpUtility.UrlEncode("<THE_PHONE_MESSAGE_TEXT_TO_BE_READ>") + "&"); //includes 'model' properties
    postData.Append(HttpUtility.UrlEncode("result_url") + "=" +         HttpUtility.UrlEncode("<MY_RESULT_URL_AS_ASMX_PAGE_SHOWN_BELOW>")); //"http://ip_address/MY_ASMX_PAGE.asmx/PlumOutboundCallback"

    ASCIIEncoding ascii = new ASCIIEncoding();
    byte[] postBytes = ascii.GetBytes(postData.ToString());

    // add post data to request
    Stream postStream = request.GetRequestStream();
    postStream.Write(postBytes, 0, postBytes.Length);
    postStream.Flush();
    postStream.Close();

    // Get response
    // Used Fiddler to deconstruct/reverse-engineer
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
        StreamReader reader = new StreamReader(response.GetResponseStream()); // Get the response stream  
        string result = reader.ReadToEnd(); // Read the contents and return as a string  

        if (result.Contains("failed"))
        {
            // Whatever error handling you want to do if your "result_url" page throws an error. I used this extensively while testing the proper way to set this up
        }
    }
}

我的.vxml文件为.aspx页面。这是发布并坐在服务器上(&#34; ip_address / MY_ASPX_PAGE.aspx&#34;)

<%Response.ContentType = "text/xml"%>
<?xml version="1.0" ?>
<vxml version="2.0">
    <form>
        <block>
            <prompt>
                <%-- Set the "Custom Call Parameters" to be THE_PHONE_MESSAGE_TEXT_TO_BE_READ --%>
                <%=request.form("call_parameters") %>  <%-- This says "Cannot resolve symbol 'request'" but just ignore it --%>
            </prompt>
        </block>
    </form>
</vxml> 

我知道这似乎写错了,但忽略了它(&#39;请求&#39;将为红色)


我的&#34; result_url&#34;是一个.asmx页面。这是发布并坐在服务器上(&#34; ip_address / MY_ASMX_PAGE.asmx / PlumOutboundCallback&#34;)

/// <summary>
/// Summary description for OutboundResultUrl
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class OutboundResultUrl : System.Web.Services.WebService
{
    [WebMethod]
    public string PlumOutboundCallback()
    {
        bool heartbeat = string.IsNullOrEmpty(HttpContext.Current.Request.Form["phone_number"]); //Plum implements a heartbeat and checks that this 'result_url' is working. A 'phone_number' has to exist in order for me to process the data FOR a call (duh) so I check to see if it is null or empty

        if (!heartbeat)
        {
            //BusinessLayer.OutboundCallback model = new BusinessLayer.OutboundCallback { phone_number = HttpContext.Current.Request.Form["phone_number"], message_reference = HttpContext.Current.Request.Form["message_reference"], call_id = Convert.ToInt32(HttpContext.Current.Request.Form["call_id"]), result = HttpContext.Current.Request.Form["result"], callee_type = HttpContext.Current.Request.Form["callee_type"], attempts = Convert.ToInt32(HttpContext.Current.Request.Form["attempts"]), last_attempt_timestamp = HttpContext.Current.Request.Form["last_attempt_timestamp"], duration = Convert.ToInt32(HttpContext.Current.Request.Form["duration"]) }; //if you're into this sort of thing
            BusinessLayer.OutboundCallback model = new BusinessLayer.OutboundCallback();
            model.phone_number = HttpContext.Current.Request.Form["phone_number"];
            model.message_reference = HttpContext.Current.Request.Form["message_reference"];
            model.call_id = Convert.ToInt32(HttpContext.Current.Request.Form["call_id"]);
            model.result = HttpContext.Current.Request.Form["result"];
            model.callee_type = HttpContext.Current.Request.Form["callee_type"];
            model.attempts = Convert.ToInt32(HttpContext.Current.Request.Form["attempts"]);
            model.last_attempt_timestamp = HttpContext.Current.Request.Form["last_attempt_timestamp"];
            model.duration = Convert.ToInt32(HttpContext.Current.Request.Form["duration"]);

            string stringResultData = string.Format("Collecting parameters posted into here. <br />Phone Number = {0}, <br />Message Reference = {1}, <br />Call ID = {2}, <br />Result = {3}, <br />Callee Type = {4}, <br />Attempts = {5}, <br />Last Attempt Timestamp = {6}, <br />Duration = {7}",
                                    model.phone_number, model.message_reference, model.callee_type, model.result, model.callee_type, model.attempts, model.last_attempt_timestamp, model.duration); //this is for debugging/testing purposes

            try
            {
                // Whatever you want to do with this data! Send it in an email, Save it to the database, etc.
            }
            catch (Exception error)
            {
                Console.WriteLine("Error: " + error);
            }
        }

        return "Plum Outbound API has posted back to this 'result_url' successfully.";
    }
}

上一步:请务必将广告系列设置为运行!更改&#34;广告系列状态&#34; http://hosting.plumgroup.com/developer_tools_outbound.php

的单元格

我真的希望这能帮助每个通过C#使用PlumVoice的人。请评论并分享任何改进或问题!