africastalkingltd / africastalking.net Goto Github PK
View Code? Open in Web Editor NEWAfrica's Talking API Wrapper for C#
Home Page: https://developers.africastalking.com
License: MIT License
Africa's Talking API Wrapper for C#
Home Page: https://developers.africastalking.com
License: MIT License
I try to run USSD on the simulator , I get the above error message and have tested it on swagger its working fine.
Basic voice services such as call
fail with generic exception.
Add Features:
Improvements:
Docs -> USSD Application
Docs -> Voice Application
Patch:
Add test cases
When fetching wallet balance for a user account, as indicated on the ReadMe doesn't work anymore;
**string fetchBalanceResponse = _atGWInstance.FetchWalletBalance();
JObject fetchBalanceResponseJson = JObject.Parse(fetchBalanceResponse);**
Instead, parse dynamic JSON
dynamic res = gw.GetUserData(); Console.WriteLine(res.UserData.balance);
This will give for example Ksh. 600.56
Sometimes I'm getting the following error message from your library: "The message is either empty or phone number is not valid", but the number is valid and exists, for example for number "+254111604133".
Is there something wrong with your logic which validates the phone number?
I'm using the AfricasTalking.NET in version 1.1.720.
Hi Team
how about building a framework to support the menu navigation and data handling
its more on the way we build websites these days ie MVC
in that way the user or other devs will use the ussd to focus on problem-solving rather than handling the routing and menu options etc
Priority:Low
private static bool IsPhoneNumber(string[] number)
{
bool valid = true;
foreach (string num in number)
{
var status = Regex.Match(num, @"^\+?(\d[\d-. ]+)?(\([\d-. ]+\))?[\d-. ]+\d{5,}$").Success;
valid = valid & status;
}
return valid;
}
Have looked at this method of validating numbers.
I would suggest use libphonenumber-csharp to enable Parsing/formatting/validating phone numbers for all countries.
It has nice goodies backed right in.
Test it here
I am using .net core web api as my callback
My initiating logic test app is
const string Username = "myusername";
const string Apikey = "myapikey";
var gateway = new AfricasTalkingGateway(Username, Apikey);
string tokenId = "tkn";
const string PhoneNumber = "+.."; my kenya number
const string Menu = "CON You're about to love C#\n1.Accept my fate\n2.No Never\n";
// Let's create a checkout token first
try
{
var tkn = gateway.CreateCheckoutToken(PhoneNumber);
if (tkn["description"] == "Success")
{
tokenId = tkn["token"];
}
// Then send user menu...
var prompt = gateway.InitiateUssdPushRequest(PhoneNumber, Menu, tokenId);
if (prompt["errorMessage"] == "None")
{
Console.WriteLine("Awesome");
}
}
catch (AfricasTalkingGatewayException ex)
{
Console.WriteLine("Woopsies : " + ex.Message);
}
My controller logic is as following
[Route("[controller]/[action]")]
[Produces("text/plain")]
public class USSDServiceController : Controller
{
public static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
[HttpPost]
public IActionResult Process([FromForm] [FromBody] UssdResponse ussdResponse)
{
IActionResult responseMessage;
string response;
Logger.Debug("Revieved Rrquest Process");
if (ussdResponse != null)
{
Logger.DebugFormat("Request content {0},{1},{2},{3}", ussdResponse.phoneNumber, ussdResponse.serviceCode, ussdResponse.sessionId, ussdResponse.text);
if (ussdResponse.text == null)
{
ussdResponse.text = "";
}
if (ussdResponse.text.Equals("", StringComparison.Ordinal))
{
response = "CON USSD Demo in Action\n";
response += "1. Do something\n";
response += "2. Do some other thing\n";
response += "3. Get my Number\n";
}
else if (ussdResponse.text.Equals("1", StringComparison.Ordinal))
{
response = "END I am doing something \n";
}
else if (ussdResponse.text.Equals("2", StringComparison.Ordinal))
{
response = "END Some other thing has been done \n";
}
else if (ussdResponse.text.Equals("3", StringComparison.Ordinal))
{
response = $"END Here is your phone number : {ussdResponse.phoneNumber} \n";
}
else
{
response = "END Invalid option \n";
}
}
else
{
Logger.Debug("Empty response");
response = "END Invalid request \n";
}
responseMessage = StatusCode((int)HttpStatusCode.Created, response);
return responseMessage;
}
}
public class UssdResponse
{
public string text { get; set; }
public string phoneNumber { get; set; }
public string sessionId { get; set; }
public string serviceCode { get; set; }
}
at AfricasTalkingCS.AfricasTalkingGateway.SendMessage(String to, String message, String from, Int32 bulkSmsMode, Hashtable options)
This Exception is thrown only with multiple recipients in the list
Code attached..
using AfricasTalkingCS;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Smsing
{
class Program
{
static void Main(string[] args)
{
// Specify your login credentials
string username = ConfigurationManager.AppSettings["username"];
string apiKey = ConfigurationManager.AppSettings["apiKey"];
const string env = "sandbox"; // For sandbox users
// Specify the numbers that you want to send to in a comma-separated list
// Please ensure you include the country code (+254 for Kenya in this case)
string recipients = "+254708440184,+254715359478";
//string recipients = "+254715359478";
// And of course we want our recipients to know what we really do
string message = "Trying multiple send sms";
// Create a new instance of our awesome gateway class
var gateway = new AfricasTalkingGateway(username, apiKey, env);
string from = null; //$from = "shortCode or senderId";
int bulkSMSMode = 1; // This should always be 1 for bulk messages
Hashtable options = new Hashtable();
options["enqueue"] = 1;
// Any gateway errors will be captured by our custom Exception class below,
// so wrap the call in a try-catch block
try
{
var sms = gateway.SendMessage(recipients, message, from, bulkSMSMode, options);
foreach (var res in sms["SMSMessageData"]["Recipients"])
{
Console.WriteLine((string)res["number"] + ": ");
Console.WriteLine((string)res["status"] + ": ");
Console.WriteLine((string)res["messageId"] + ": ");
Console.WriteLine((string)res["cost"] + ": ");
}
Console.ReadLine();
}
catch (AfricasTalkingGatewayException exception)
{
Console.WriteLine(exception);
}
Console.ReadLine();
}
}
}
Kindly consider updating the library to be supported by .Net Core
Hi, this check will fail when a string in null
since you can't call .Length
on a null string object.
I would suggest using String.IsNullOrWhiteSpace(String) to do the check.
You can create a test case wherein you pass null for phoneNumber/shortCode/keyWord and see that a NullObjectReferenceException
is thrown instead of the anticipated AfricasTalkingGatewayException
Add unsupported country response for requests outside Nigeria.
See #40
All payment transactions accept decimal
types as params : C2B takes integer
as a parameter.
Unable to add payment metadata as described under the following sections of the documentation
Return all API responses as JSON objects.
{ APIResponse : { "stuff: : "stuff_value", "some" : "more_stuff" } }
providerChannel String Optional: The channel the payment will be made from e.g a paybill number. The payment channel must be mapped to your Africa’s Talking payment product. If not specified, a default provider channel will be used.
that is missing from the MobileB2CRecepient object.
I created a dotnet core API to provide the callback URL for the USSD Service. But the API does not work the USSD Services gives the error below:
My controller is designed as follows:
[Route("api/[controller]")]
[ApiController]
public class ServicesController : ControllerBase
{
[Route("ussd")]
[HttpPost]
public IActionResult USSDService([FromBody] USSDResponse serviceResponse)
{
}
}
However the USSD service works when the method is changed as follows:
public IActionResult USSDService(string serviceResponse)
{
}
But the issue is that no object is passed from the USSD Service to this method
Hello, I implemented initiateussdpushrequest on my codebase and tried debugging but i was getting a failed response to configure callback url on my dashboard. I have created a channel and registered a callback url on the test sandbox. What could be the issue? Kindly help resolve
Fix Azure DevOps Tests.
ADO fails to detect tests
1 Add sample JSON responses from API.
2. Fold sample code using <summary>
tag on Markdown
{apiSays : { "stuff" : "sent_from_api", "more" : "stuff" } }
var sampleCode = this.Display(sample);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.