.NET 4.5 client library for Fone Dynamics services. This library currently supports messaging only.
The easiest way to get started is to use the NuGet Package Manager to install the FoneDynamics package.
You can also use the Package Manager Console by running the following command.
Install-Package FoneDynamics
There are two ways to set up authentication with your Fone Dynamics account.
In your App.config or Web.config file, under the appSettings element, add the following keys.
<add key="FoneDynamics.AccountSid" value="YOUR_ACCOUNT_SID" />
<add key="FoneDynamics.Token" value="YOUR_TOKEN" />
<add key="FoneDynamics.DefaultPropertySid" value="YOUR_PROPERTY_SID" />Note that the FoneDynamics.DefaultPropertySid is optional. If you have multiple properties you should omit this setting and specify it explicitly when interacting with the client library.
You can define your authentication credentials on startup of your application by initializing FoneDynamicsClient as below. This will statically initialize authentication for the entire application.
// initialize the Fone Dynamics client library
FoneDynamicsClient.Initialize("YOUR_ACCOUNT_SID", "YOUR_TOKEN", "OPTIONAL_DEFAULT_PROPERTY_SID");Alternatively, if you need to interact with multiple Fone Dynamics accounts, you can construct an instance of FoneDynamicsClient for a specific account and explicitly pass this as an argument when interacting with the client library.
To send a message, use MessageResource.Send(). The response will contain details of the message that has been sent.
// send the message. use from: null to auto-allocate a sender ID
MessageResource msg = MessageResource.Send("+61499999999", from: null, text: "Hello world!");
// log details of sent message to console
Console.WriteLine($"Sent message with MessageSid: {msg.MessageSid} From: {msg.From} To: {msg.To} Text: {msg.Text}");To get the details of a message that has been sent or received, use MessageResource.Get().
// get a message by its MessageSid
string messageSid = "MGTBUEHNLFOOHNSIOCSAQRRUKLMEZSLE";
MessageResource msg = MessageResource.Get(messageSid);
// log details of message to console
Console.WriteLine($"Fetched message. MessageSid: {msg.MessageSid} From: {msg.From} To: {msg.To} Text: {msg.Text}");To send a batch of messages, use the overload of MessageResource.Send() that accepts an IEnumerable<MessageResource>. Individual messages within the batch can succeed or fail. The return value is a list of messages that have been sent and failed, and you can determine whether a message succeeded by checking the Successful property against a message in the return list.
// construct and messages
List<MessageResource> messages = new List<MessageResource>()
{
new MessageResource("+61499999999", from: "FDX", text: "and a one"),
new MessageResource("+61499999999", from: "FDX", text: "and a two"),
new MessageResource("+61499999999", from: "FDX", text: "and a one, two, three!")
};
var responses = MessageResource.Send(messages);
// write responses to console
for (int i = 0; i < responses.Count; i++)
{
var response = responses[i];
if (response.Successful)
{
Console.WriteLine($"Message #{i} successful! MessageSid: {response.MessageSid}");
}
else
{
Console.WriteLine($"Message #{i} failed! {response.ErrorCode}: {response.ErrorMessage}");
}
}IntelliSense documentation is included for all methods and parameters.
For additional documentation, please see the Fone Dynamics REST API Documentation.