.NET client library for Telerivet REST API
C#
Switch branches/tags
Nothing to show
Clone or download
youngj add API method for sending multiple messages; support gzip compressio…
…n for HTTP requests and responses; remove deprecated methods for mobile money receipts
Latest commit 7ff3305 Jun 12, 2018

README.md

.NET client library for Telerivet REST API

http://telerivet.com/api

https://www.nuget.org/packages/Telerivet.NET/

Overview

This library makes it easy to integrate your .NET application with Telerivet. You can use it to:

  • send SMS messages via an Android phone or SMS gateway service
  • update contact information in Telerivet (e.g. from a signup form on your own website)
  • add or remove contacts from groups
  • export your message/contact data from Telerivet into your own systems
  • schedule messages to be sent at a later time
  • control automated services
  • much more

All API methods are fully documented at https://telerivet.com/api/rest/dotnet , as well as in the comments of the C# source files.

System Requirements

.NET framework 4.5 or higher

Installation

To install the library, run the following command in the Package Manager Console in Visual Studio:

PM> Install-Package Telerivet.NET -Version 1.4.0

Example Usage

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerivet.Client;
using Newtonsoft.Json.Linq;

namespace ExampleNamespace
{
    public class ExampleClass
    {
        public async Task foo()
        {
            TelerivetAPI tr = new TelerivetAPI("YOUR_API_KEY");
            Project project = tr.InitProjectById("PROJECT_ID");

            // send message
            Message sent_msg = await project.SendMessageAsync(Util.Options(
                "content", "hello world",
                "to_number", "+16505550123"
            ));


            // import contact and add to group

            Contact contact = await project.GetOrCreateContactAsync(Util.Options(
                "name", "John Smith",
                "phone_number", "5550123",
                "vars", Util.Options("email", "jsmith@example.com", "birthdate", "1953-01-04")
            ));

            Group group = await project.GetOrCreateGroupAsync("Subscribers");
            await contact.AddToGroupAsync(group);

            // query contact information

            String namePrefix = "John";
            APICursor<Contact> query = project.QueryContacts(Util.Options(
                "name", Util.Options("prefix", namePrefix),
                "sort", "name"
            ));

            int count = await query.CountAsync();

            List<Contact> contacts = await query.Limit(50).AllAsync();

            Console.WriteLine(count + " contacts matching " + namePrefix + ":");
            foreach (Contact c in contacts)
            {
                Console.WriteLine(c.Name + " " + c.PhoneNumber + " " + c.Vars.Get("birthdate"));
            }
        }
    }
}