Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

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

Closed
KamranShahid opened this issue Oct 28, 2019 · 10 comments
Assignees

Comments

@KamranShahid
Copy link

KamranShahid commented Oct 28, 2019

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
Copy link
Author

KamranShahid commented Oct 28, 2019

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 TheBeachMaster self-assigned this Oct 28, 2019
@TheBeachMaster
Copy link
Contributor

Hello @KamranShahid

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

@KamranShahid
Copy link
Author

KamranShahid commented Oct 28, 2019

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
Copy link
Contributor

TheBeachMaster commented Oct 28, 2019

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
Copy link
Author

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
Copy link
Contributor

This has been noted.

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

@KamranShahid
Copy link
Author

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

@TheBeachMaster
Copy link
Contributor

We'll add these responses

@KamranShahid
Copy link
Author

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
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants