Skip to content

Reach Messaging API - Quickstart - C#

Sending SMS with the Reach Messaging API from TalkyLabs is made possible with just a few lines of C# code.

In what follows, we provide a step-by-step guide to facilitate your debut. In this quickstart, you will learn how to:

Information Circle
  • Sign up for the Reach platform

  • Create an applet

  • Retrieve your API credentials

  • Verify your phone number

  • Send a SMS

Sign-up / Sign-in

Information Circle

You can skip this section if you already have an account on the Reach platform.

You can sign up for an account on the Reach platform here. You will be asked to verify your email address to activate your account.

Create an applet

Information Circle

You can skip this section if you already have an applet and want to use it here.

An applet can be viewed as a subaccount or a development environment within the Reach platform. It allows you to regroup your operations in the Reach platform based on your customer segments, e.g., by country. You can have more than one applet associated with your account.

Creating an applet is just as simple as clicking a button and specifying the applet name as well as the operating country, that is the country where most of the customers targeted by the operations that will be performed under this applet reside.

Retrieve your API credentials

After accessing your applet, you can retrieve your API credentials by visiting Settings -> API from the left side menu.

As you will notice, you will gain access to your API User as well as your Test and Live API Key. Recall that the Test API key is for the sandbox mode where you can emulate sending messages while the Live API key is for sending messages for real.

Finally, note that it is possible to re-generate your API keys as you go.

Verify your phone number

Information Circle

You can skip this section if you already have a verified number.

With an applet, you can emulate sending messages in a sandbox mode by using whatever valid phone numbers you want. However, for sending real messages, you can only use phone numbers that you own.

To demonstrate the ownership of a phone number, you need to verify it. Within an applet, visit the section Phone numbers -> Verified numbers from the left side menu to add your number and start a verification process.

Warning

Once the number is verified, it will be valid for a period of time. For now, that period is three months and this can changed without prior notice. You will have to re-verify the number to continue use it after that period of time.

Install the client library

Information Circle

If you already have the C# client library installed, you can skip this step and get straight to sending your first message.

If you are developing with the .NET Framework, you have to make sure that Visual Studio is installed.

On the other hand, if you are developing with the .NET core, you have to make sure you have .NET Core installed on your computer. This could be checked by running the following command:

dotnet --version

If .NET Core is installed, you would see something like:

7.0.400

In either case, you need to create a project and use the NuGet package manager to install the C# client library.

With Visual Studio IDE (.NET Framework)

From within Visual Studio, you can use the NuGet GUI to search for and install the Reach-TalkyLabs NuGet package. Or, as a shortcut, simply type the following command into the Package Manager Console:

Install-Package Reach-TalkyLabs

With .NET Core Command Line Tools

If you are building with the .NET Core command line tools, then you can run the following command from within your project directory:

dotnet add package Reach-TalkyLabs

Send a message

Now that the C# client library is installed, we can send an SMS using a valid verified number registered in the applet. Create a file name SendMessage.cs and paste in it the code sample below.

using System;
using Reach;
using Reach.Rest.Api.Messaging;


class SendMessage
{
    static void Main(string[] args)
    {
        string apiUser = Environment.GetEnvironmentVariable("REACH_TALKYLABS_API_USER");
        string apiKey = Environment.GetEnvironmentVariable("REACH_TALKYLABS_API_KEY");
        
        ReachClient.Init(apiUser, apiKey);

        var message = MessagingItemResource.Send(
            dest: "+237671234567",
            src: "+237691234567",
            body: "Hello World! This is a sms message."
        );

        Console.WriteLine(message.MessageId);
    }
}      

Replace the src phone number with your verified number and the dest phone number with the number you want to send the message to. The phone numbers must be in the E.164 format.

Also, use your API credentials to replace the placeholder values for apiUser and apiKey. Remember to use your Live API key.

Warning

For getting started, it is okay to hardcode your credentials in the file. However, it is highly recommend to use environment variables to store sensitive data instead.

Save the file and either run your project in Visual Studio (.NET Framework), or run the following command in your terminal (.NET Core):

dotnet run

That's it! In a few moments, your message will be delivered to the destination phone number.