Impementing Clickatell CallBack in ASP.NET using C#.NET

旧巷老猫 提交于 2019-12-08 18:38:28
Walter Lockhart

I solved the problem by placing the callback and deliver_ack parameters with the startbatch command and not the quicksend command. This seems to work. So here is what I have inside the C#.NET function that starts the batch:

protected string get_batch_id(string session_id, string message_body)
{
    // Declare a WebClient.
    WebClient client = new WebClient();

    // Add a User Agent Header.
    client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)");

    // Add the session_id to the Query String.
    client.QueryString.Add("session_id", session_id);

    // Add the template to the Query String.
    client.QueryString.Add("template", message_body);

    // Add the callback to the Query String.
    client.QueryString.Add("callback", "3");

    // Add the deliv_ack to the Query String.
    client.QueryString.Add("deliv_ack", "1");

    // Declare the baseurl.
    string baseurl = "http://api.clickatell.com/http_batch/startbatch";

    // Open the baseurl.
    Stream data = client.OpenRead(baseurl);

    // Declare and instantiate a StreamReader to retrieve the results of executing the startbatch command.
    StreamReader reader = new StreamReader(data);

    // Parse and split the returned string into the returned_strings array.
    string[] returned_strings = reader.ReadToEnd().Split(' ');

    // Retrieve the batch_id from the (second element of the) returned_strings array.
    string batch_id = returned_strings[1].ToString();

    // Close the Stream.
    data.Close();

    // Close the Reader.
    reader.Close();

    // Return the batch_id.
    return (batch_id);
}

Phew!

So I've also managed to get the following functionality successfully coded up in ASP.NET using C#.NET:

  1. Send a message to a single recipient;
  2. Send the same message to multiple recipients;
  3. Send a personalised message to a single recipient;
  4. Send a personalised message to multiple recipients;

Along the way I've noticed that there aren't too many cliackatell code samples in ASP.NET using C#.NET.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!