Giter Site home page Giter Site logo

hnjm / plivo-dotnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from plivo/plivo-dotnet

1.0 3.0 0.0 1.79 MB

A .NET SDK to make voice calls & send SMS using Plivo and to generate Plivo XML

License: MIT License

C# 99.76% Shell 0.17% Dockerfile 0.07% Makefile 0.01%

plivo-dotnet's Introduction

plivo-dotnet

UnitTest

The Plivo .NET SDK makes it simpler to integrate communications into your .NET applications using the Plivo REST API. Using the SDK, you will be able to make voice calls, send SMS and generate Plivo XML to control your call flows.

Supported .NET versions: This SDK was written targeting at .NET Standard 1.3 & .NET Standard 2.0, and thus works with .NET Framework 4.6+ and .NET Core 1.0+. Check here to know about all the other supported platforms.

Installation

You can install this SDK either by referencing the .dll file or using NuGet.

Use the following line to install the latest SDK using the NuGet CLI.

PM> Install-Package Plivo -Version 4.2.5

You can also use the .NET CLI to install this package as follows

> dotnet add package Plivo --version 4.2.5

Getting started

Authentication

To make the API requests, you need to create a PlivoApi instance and provide it with authentication credentials (which can be found at https://manage.plivo.com/dashboard/).

var api = new PlivoApi("<auth_id>", "<auth_token>");

The Basics

The SDK uses consistent interfaces to create, retrieve, update, delete and list resources. The pattern followed is as follows:

api.Resource.Create(params);
api.Resource.Get(params);
api.Resource.Update(identifier, params);
api.Resource.Delete(identifier);
api.Resource.List();

Using api.Resource.List() would list the first 20 resources by default (which is the first page, with limit as 20, and offset as 0). To get more, you will have to use limit and offset to get the second page of resources.

Examples

Send a message

internal class Program
{
    public static void Main(string[] args)
    {
        var api = new PlivoApi("<auth_id>", "<auth_token>");
        var response = api.Message.Create(
            src:"14156667778",
            dst:"14156667777",
            text:"Hello, this is a sample text from Plivo"
        );
        Console.WriteLine(response);
    }
}

Make a call

internal class Program
{
    public static void Main(string[] args)
    {
        var api = new PlivoApi("<auth_id>", "<auth_token>");
        var response = api.Call.Create(
            to:new List<String>{"the_to_number"},
            from:"the_from_number",
            answerMethod:"GET",
            answerUrl:"https://answer.url"
        );
        Console.WriteLine(response);
    }
}

Lookup a number

internal class Program
{
    public static void Main(string[] args)
    {
        var api = new PlivoApi("<auth_id>", "<auth_token>");
        var response = api.Lookup.Get("phone_number_here");
        Console.WriteLine(response);
    }
}

Generate Plivo XML

class MainClass
{
    public static void Main(string[] args)
    {
        Plivo.XML.Response response = new Plivo.XML.Response();
        response.AddSpeak("Hello, world!",
                          new Dictionary<string, string>() { });
        Console.WriteLine(response.ToString());
    }
}

This generates the following XML:

<Response>
  <Speak>Hello, world!</Speak>
</Response>

More examples

Refer to the Plivo API Reference for more examples.

Reporting issues

Report any feedback or problems with this version by opening an issue on Github.

Local Development

Note: Requires latest versions of Docker & Docker-Compose. If you're on MacOS, ensure Docker Desktop is running.

  1. Export the following environment variables in your host machine:
export PLIVO_AUTH_ID=<your_auth_id>
export PLIVO_AUTH_TOKEN=<your_auth_token>
export PLIVO_API_DEV_HOST=<plivoapi_dev_endpoint>
export PLIVO_API_PROD_HOST=<plivoapi_public_endpoint>
  1. Run make build. This will create a docker container in which the sdk will be setup and dependencies will be installed.

The entrypoint of the docker container will be the setup_sdk.sh script. The script will handle all the necessary changes required for local development. It will also package the sdk and reinstall it as a dependecy for the test program.

  1. The above command will print the docker container id (and instructions to connect to it) to stdout.
  2. The testing code can be added to <sdk_dir_path>/dotnet-sdk-test/Program.cs in host
    (or /usr/src/app/dotnet-sdk-test/Program.cs in container)
  3. The sdk directory will be mounted as a volume in the container. So any changes in the sdk code will also be reflected inside the container. However, when any change is made, the dependencies for the test program need to be re-installed. To do that:
    • Either restart the docker container
    • Or Run the setup_sdk.sh script

plivo-dotnet's People

Contributors

abinaya-shunmugavel avatar abrolnalin avatar ajay-plivo avatar alexk01 avatar bhuvanvenkat-plivo avatar dhruv-chauhan avatar huzaif-plivo avatar kalyan-plivo avatar kanishka2104 avatar kapilp93 avatar koushik-ayila avatar kritarth-plivo avatar kunal-plivo avatar lsaitharun avatar manish-plivo avatar manjunath-plivo avatar mohsin-plivo avatar narayana-plivo avatar nikhil-plivo avatar nirmitijain avatar nixonsam avatar plivo-sdks avatar prashantp-plivo avatar renoldthomas-plivo avatar shubham-plivo avatar solidclouddev avatar solidcloudio avatar sreyantha-plivo avatar varshit97plivo avatar vishesh-plivo avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.