Skip to content

messagemedia/messages-csharp-sdk

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e7fa876 Β· Sep 19, 2018

History

72 Commits
Sep 10, 2018
May 16, 2018
Sep 10, 2018
Nov 29, 2017
May 31, 2018
Nov 6, 2017
Apr 15, 2018
Nov 23, 2017
Sep 19, 2018
Nov 6, 2017
Dec 5, 2017

Repository files navigation

MessageMedia Messages C# SDK

Travis Build Status Pull Requests Welcome NuGet version

The MessageMedia Messages API provides a number of endpoints for building powerful two-way messaging applications.

Isometric

Table of Contents

πŸ” Authentication

Authentication is done via API keys. Sign up at https://developers.messagemedia.com/register/ to get your API keys.

Requests are authenticated using HTTP Basic Auth or HMAC. Provide your API key as the auth_user_name and API secret as the auth_password.

⁉️ Errors

Our API returns standard HTTP success or error status codes. For errors, we will also include extra information about what went wrong encoded in the response as JSON. The most common status codes are listed below.

HTTP Status Codes

Code Title Description
400 Invalid Request The request was invalid
401 Unauthorized Your API credentials are invalid
403 Disabled feature Feature not enabled
404 Not Found The resource does not exist
50X Internal Server Error An error occurred with our API

πŸ“° Information

Slack and Mailing List

If you have any questions, comments, or concerns, please join our Slack channel: https://developers.messagemedia.com/collaborate/slack/

Alternatively you can email us at: [email protected]

Bug reports

If you discover a problem with the SDK, we would like to know about it. You can raise an issue or send an email to: [email protected]

Contributing

We welcome your thoughts on how we could best provide you with SDKs that would simplify how you consume our services in your application. You can fork and create pull requests for any features you would like to see or raise an issue

⭐ Installation

Install via NuGet by:

PM> Install-Package MessageMedia.SDK.Messages -Version 1.1.2

Alternatively, right-click on your solution and click "Manage NuGet Packages...", then click browse and search for MessageMedia.

Visual Studio Mac: Project -> Add NuGet Packages -> Search for 'MessageMedia'

🎬 Get Started

It's easy to get started. Simply enter the API Key and secret you obtained from the MessageMedia Developers Portal into the code snippet below and a mobile number you wish to send to. Please note this SDK is not supported for .NET Framework applications.

Send an SMS

Destination numbers (destination_number) should be in the E.164 format. For example, +61491570156.

using System;
using System.Linq;
using MessageMedia.Messages;
using MessageMedia.Messages.Controllers;
using MessageMedia.Messages.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace TestCSharpSDK
{
    class Program
    {
        static void Main(string[] args)
        {
            // Configure your credentials (Note, these can be pulled from the environment variables as well)
            String basicAuthUserName = "YOUR_API_KEY";
            String basicAuthPassword = "YOUR_API_SECRET";
            bool useHmacAuthentication = false; //Change this to true if you are using HMAC keys
            
            // Instantiate the client
            MessageMediaMessagesClient client = new MessageMediaMessagesClient(basicAuthUserName, basicAuthPassword, useHmacAuthentication);
            IMessagesController messages = client.Messages;

            var request = new SendMessagesRequest() {
				Messages = new []{
					new Message() {
						Content = "Greetings from MessageMedia!",
						DestinationNumber = "YOUR_MOBILE_NUMBER"
					}
				}
			};
			

            SendMessagesResponse result = messages.CreateSendMessages(request);
            Message message = result.Messages.First();
			
            Console.WriteLine("Status: {0}, Message Id: {1}", message.Status, message.MessageId);
            Console.ReadKey();
        }
    }
}

Send an MMS

Destination numbers (destination_number) should be in the E.164 format. For example, +61491570156.

using System;
using System.Linq;
using MessageMedia.Messages;
using MessageMedia.Messages.Controllers;
using MessageMedia.Messages.Models;

namespace TestCSharpSDK
{
    class Program
    {
        static void Main(string[] args)
        {
            // Configure your credentials (Note, these can be pulled from the environment variables as well)
            String basicAuthUserName = "YOUR_API_KEY";
            String basicAuthPassword = "YOUR_API_SECRET";
            bool useHmacAuthentication = false; //Change this to true if you are using HMAC keys
            
            // Instantiate the client
            MessageMediaMessagesClient client = new MessageMediaMessagesClient(basicAuthUserName, basicAuthPassword, useHmacAuthentication);
            IMessagesController messages = client.Messages;

            // Perform API call
            var request = new SendMessagesRequest()
            {
                Messages = new[]
                {
                    new Message()
                    {
                        Format = MessageFormat.MMS,
                        Content = "Greets from MessageMedia!",
                        DestinationNumber = "YOUR_MOBILE_NUMBER",
                        Media = new[]
                            {"https://upload.wikimedia.org/wikipedia/commons/6/6a/L80385-flash-superhero-logo-1544.png"}

                    }
                }
            };

            SendMessagesResponse result = messages.CreateSendMessages(request);
            Message message = result.Messages.First();
			
            Console.WriteLine("Status: {0}, Message Id: {1}", message.Status, message.MessageId);
            Console.ReadKey();
        }
    }
}

Get Status of a Message

You can get a messsage ID from a sent message by looking at the message_id from the response of the above example.

using System;
using MessageMedia.Messages;
using MessageMedia.Messages.Controllers;
using MessageMedia.Messages.Models;

namespace TestCSharpSDK
{
    class Program
    {
        static void Main(string[] args)
        {
            // Configure your credentials (Note, these can be pulled from the environment variables as well)
            String basicAuthUserName = "YOUR_API_KEY";
            String basicAuthPassword = "YOUR_API_SECRET";
            bool useHmacAuthentication = false; //Change this to true if you are using HMAC keys
            
            // Instantiate the client
            MessageMediaMessagesClient client = new MessageMediaMessagesClient(basicAuthUserName, basicAuthPassword, useHmacAuthentication);
            IMessagesController messages = client.Messages;

            string messageId = "YOUR_MESSAGE_ID";
            dynamic result = messages.GetMessageStatus(messageId);

            string msg = Newtonsoft.Json.JsonConvert.SerializeObject(result);
            Console.WriteLine(msg);
        }
    }
}

Get replies to a message

You can check for replies that are sent to your messages

using System;
using MessageMedia.Messages;
using MessageMedia.Messages.Controllers;
using MessageMedia.Messages.Models;

namespace TestCSharpSDK
{
    class Program
    {
        static void Main(string[] args)
        {
            // Configure your credentials (Note, these can be pulled from the environment variables as well)
            String basicAuthUserName = "YOUR_API_KEY";
            String basicAuthPassword = "YOUR_API_SECRET";
            bool useHmacAuthentication = false; //Change this to true if you are using HMAC keys
            
            // Instantiate the client
            MessageMediaMessagesClient client = new MessageMediaMessagesClient(basicAuthUserName, basicAuthPassword, useHmacAuthentication);
            IRepliesController replies = client.Replies;

            MessageMedia.Messages.Models.CheckRepliesResponse result = replies.GetCheckReplies();

            string msg = Newtonsoft.Json.JsonConvert.SerializeObject(result);
            Console.WriteLine(msg);
        }
    }
}

Check Delivery Reports

This endpoint allows you to check for delivery reports to inbound and outbound messages.

using System;
using MessageMedia.Messages;
using MessageMedia.Messages.Controllers;
using MessageMedia.Messages.Models;

namespace TestCSharpSDK
{
    class Program
    {
        static void Main(string[] args)
        {
            // Configure your credentials (Note, these can be pulled from the environment variables as well)
            String basicAuthUserName = "YOUR_API_KEY";
            String basicAuthPassword = "YOUR_API_SECRET";
            bool useHmacAuthentication = false; //Change this to true if you are using HMAC keys
            
            // Instantiate the client
            MessageMediaMessagesClient client = new MessageMediaMessagesClient(basicAuthUserName, basicAuthPassword, useHmacAuthentication);
            IDeliveryReportsController deliveryReports = client.DeliveryReports;

            MessageMedia.Messages.Models.CheckDeliveryReportsResponse result = deliveryReports.GetCheckDeliveryReports();

            string msg = Newtonsoft.Json.JsonConvert.SerializeObject(result);
            Console.WriteLine(msg);
        }
    }
}

πŸ“• API Reference Documentation

Check out the full API documentation for more detailed information.

πŸ˜• Need help?

Please contact developer support at [email protected] or check out the developer portal at developers.messagemedia.com

πŸ“ƒ License

Apache License. See the LICENSE file.