Using this guide, you can set up a development environment in five minutes to trigger API requests related to our Messaging API. It also shows how to send and receive messages using tunneling software to expose the local dev server to the public internet.
To get started, install and set up .NET Framework 4.6 or higher and Plivo’s .NET SDK.
You can check whether you already have .NET Framework installed under macOS or Linux and what version is installed by running the command dotnet --version in a terminal window. Under Windows there are several ways to check. If you don’t have it or need a more current version, download and install it.
To install the Plivo .NET SDK:
Now you can create a file in the project directory and execute code to trigger any Plivo API. Here’s some example code that sends an SMS message. Open the Program.cs
file in the CS project and paste into it this code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System;
using System.Collections.Generic;
using Plivo;
namespace testplivo
{
internal class Program
{
public static void Main(string[] args)
{
var api = new PlivoApi("<auth_id>","<auth_token>");
var response = api.Message.Create(
src: "<caller_id>",
dst: new List<String> { "<destination_number" },
text: "Hello, from .NET Framework!"
);
Console.WriteLine(response);
}
}
}
Before starting the application, edit Properties/launchSettings.json and set applicationUrl to
"applicationUrl": "http://localhost:5000/"
Save the file and run it.
You should see your basic server application in action on http://localhost:5000/receivesms/. You can follow the same approach to trigger other API requests. Refer to our detailed API reference to see all the API requests available on our Voice API platform.
Now that we’ve sent a message, let’s set up a .Net Framework application to handle incoming messages.
Plivo supports receiving SMS text messages in several countries (see complete SMS API coverage). When someone sends a text message to a Plivo phone number, you can receive it on your server by setting a Message URL in your Plivo application. Plivo sends the message, along with other parameters, to your Message URL.
Navigate to the Controllers directory in the ReceiveSms application, create a Controller named ReceiveSmsController.cs, and paste into it this code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using Microsoft.AspNetCore.Mvc;
namespace ReceiveSms.Controllers
{
public class ReceiveSmsController : Controller
{
// GET: /<controller>/
public String Index()
{
String from_number = Request.Form["From"];
String to_number = Request.Form["To"];
String text = Request.Form["Text"];
Console.WriteLine("Message received - From: {0}, To: {1}, Text: {2}", from_number, to_number, text);
return "Message received";
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System;
using Microsoft.AspNetCore.Mvc;
namespace ReceiveSms.Controllers
{
public class ReceiveSmsController : Controller
{
// GET: /<controller>/
public String Index()
{
String from_number = Request.Form["From"];
String to_number = Request.Form["To"];
String text = Request.Form["Text"];
String media_url = Request.Form["Media0"];
Console.WriteLine("Message received - From: {0}, To: {1}, Text: {2}, Media: {3}", from_number, to_number, text, media_url);
return "Message received";
}
}
}
Finally, before starting the application, edit Properties/launchSettings.json and set applicationUrl to
"applicationUrl": "http://localhost:5000/"
Run the project, and you should see your basic server application in action on http://localhost:5000/receivesms/
To receive incoming messages, your local server must connect with Plivo API services. For that, we recommend using ngrok, which exposes local servers running behind NATs and firewalls to the public internet over secure tunnels. Using ngrok, you can set webhooks that can talk to the Plivo server.
Install ngrok and run it on the command line, specifying the port that hosts the application on which you want to receive messages (5000 in this case):
./ngrok http 5000
This starts the ngrok server on your local server. Ngrok will display a forwarding link that you can use as a webhook to access your local server over the public network.
Now people can send messages to your Plivo number.
You can follow the same approach to serve other XML documents to manage other call flows. Refer to our detailed XML reference to see all the XML elements available on our Messaging API platform.