AfricasTalkingLtd / africastalking.Net

Africa's Talking API Wrapper for C#
https://developers.africastalking.com
MIT License
18 stars 38 forks source link

Getting error Unexpected character encountered while parsing value: T. Path '', line 0, position 0. at Newtonsoft.Json.JsonTextReader.ParseValue() #40

Closed KamranShahid closed 4 years ago

KamranShahid commented 4 years ago

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; }

}           
KamranShahid commented 4 years ago

Also sometime i get error "One or some of the arguments supplied are invalid." When i am trying with simulator my request works Also I have just Read a line at https://github.com/AfricasTalkingLtd/africastalking.Net

USSD push currently works in Nigeria only

Please confirm. I am testing with Kenya Sim

Thanks

TheBeachMaster commented 4 years ago

Hello @KamranShahid

Could you confirm that you are trying to test USSD push on a Kenyan number?

KamranShahid commented 4 years ago

Yes. One Additional thing about that number is it is on roaming in other country. But I have also just tried out with non roaming Kenyan number and it is also not working

TheBeachMaster commented 4 years ago

Note that USSD is available in all countries we have a presence in, the only issue is that USSD push is only available in Nigeria.

KamranShahid commented 4 years ago

Note that USSD is available in all countries we have a presence in, the only issue is that USSD push is only available in Nigeria.

I have asked this thing quite early. Atleast Api response should be proper

TheBeachMaster commented 4 years ago

This has been noted.

Please let us know if you encounter any other issues with our API.

KamranShahid commented 4 years ago

Sure. Looks like Api response for non supporting country numbers is not proper. Arthur thanks for the support

TheBeachMaster commented 4 years ago

We'll add these responses

KamranShahid commented 4 years ago

We'll add these responses

Just a small advice is to close the issue when you have added the support for proper response. Thanks

TheBeachMaster commented 4 years ago

We'll add these responses

Just a small advice is to close the issue when you have added the support for proper response. Thanks

See #41