kokkoon / BotConnectorAPI

2 stars 8 forks source link

NullReferenceException: Object reference not set to an instance of an object #1

Closed sydrawat01 closed 1 year ago

sydrawat01 commented 1 year ago

I was following the following Twillio blog to connect Power Virtual Agents (PVA) bots to Twilio using a Relay Bot in C# (link).

I cloned this project as mentioned in the blog, where I proceeded to update the parameters to the appSettings.json file with the values collected from the PVA bot.

I then ran the C# project using the dotnet watch run from within the project folder in my terminal. This loaded up a Swagger page on http://localhost:5157/swagger/index.html, which I then used to test the relay bot.

After filling in the From and Body parameters in the request, I executed the API request, which failed.

Here is the error log from the terminal:

Please note that I have changed the from number to something random, but in the actual request, I did put in the correct Twilio phone number.

From: +19999999999, hi
s_tokens: eyJhbGciOiJSUzI1NiIsImtpZCI6Ii1FMmRMMlhXZ2tCSTNmLV93MTNrWUE0YXBXTSIsIng1dCI6Ii1FMmRMMlhXZ2tCSTNmLV93MTNrWUE0YXBXTSIsInR5cCI6IkpXVCJ9.eyJib3QiOiJmOWFkYzJiZC01YmZjLTRiNWUtYTA3Zi1kYzY4OTdjMDQ1YmQiLCJzaXRlIjoiSEp6eE1STjBTcGciLCJjb252IjoiNFRTRHNxWUlGZHEzT0FaRFRCOXdMei1ldSIsInVzZXIiOiIyOTNkZGNiMi0zNzA5LTRlNDItOGNlZS00NTUxNmY3YTFiNDEiLCJuYmYiOjE2ODQzNDczMDksImV4cCI6MTY4NDM1MDkwOSwiaXNzIjoiaHR0cHM6Ly9kaXJlY3RsaW5lLmJvdGZyYW1ld29yay5jb20vIiwiYXVkIjoiaHR0cHM6Ly9kaXJlY3RsaW5lLmJvdGZyYW1ld29yay5jb20vIn0.jYx9HCxOFTYNS68MwIc-XejfiKRQF08zLQMv4RCIIukaSHE-fbljFw8jHjhqgTTmEMCyCxGfOmfa36Kv1kJQ8VXkUluOtReolyONVtMjvozs_1Tyif33CVFKDfW9ef-iyMCVWmOOEi5JO9sPoREASbjjJDzTSNLwKsdTjnEUtcmFMiLuOEtB6mm1YMtuNOpej4fWL70jiB94o5UepbSx8dKdvk3qpe_K_PofVuVypwiGOgkSKTgkMpqEqUnzxLQqPI1qPJnSV635k_4I2P_x1cDMjUQ2d-g5AKhqeEtPNfqcbt4ULD76_cdslTWQHOE5Ky6z7LggOHPmJKtXsxPnKg
token: eyJhbGciOiJSUzI1NiIsImtpZCI6Ii1FMmRMMlhXZ2tCSTNmLV93MTNrWUE0YXBXTSIsIng1dCI6Ii1FMmRMMlhXZ2tCSTNmLV93MTNrWUE0YXBXTSIsInR5cCI6IkpXVCJ9.eyJib3QiOiJmOWFkYzJiZC01YmZjLTRiNWUtYTA3Zi1kYzY4OTdjMDQ1YmQiLCJzaXRlIjoiSEp6eE1STjBTcGciLCJjb252IjoiNFRTRHNxWUlGZHEzT0FaRFRCOXdMei1ldSIsInVzZXIiOiIyOTNkZGNiMi0zNzA5LTRlNDItOGNlZS00NTUxNmY3YTFiNDEiLCJuYmYiOjE2ODQzNDczMDksImV4cCI6MTY4NDM1MDkwOSwiaXNzIjoiaHR0cHM6Ly9kaXJlY3RsaW5lLmJvdGZyYW1ld29yay5jb20vIiwiYXVkIjoiaHR0cHM6Ly9kaXJlY3RsaW5lLmJvdGZyYW1ld29yay5jb20vIn0.jYx9HCxOFTYNS68MwIc-XejfiKRQF08zLQMv4RCIIukaSHE-fbljFw8jHjhqgTTmEMCyCxGfOmfa36Kv1kJQ8VXkUluOtReolyONVtMjvozs_1Tyif33CVFKDfW9ef-iyMCVWmOOEi5JO9sPoREASbjjJDzTSNLwKsdTjnEUtcmFMiLuOEtB6mm1YMtuNOpej4fWL70jiB94o5UepbSx8dKdvk3qpe_K_PofVuVypwiGOgkSKTgkMpqEqUnzxLQqPI1qPJnSV635k_4I2P_x1cDMjUQ2d-g5AKhqeEtPNfqcbt4ULD76_cdslTWQHOE5Ky6z7LggOHPmJKtXsxPnKg
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.NullReferenceException: Object reference not set to an instance of an object.
at myBotConnector.Controllers.BotConnectorController.StartConversation(String inputMsg, String token) in C:\Users\rawatsid\Documents\BotConnectorAPI\Controllers\myBotConnectorController.cs:line 67
at myBotConnector.Controllers.BotConnectorController.StartBot(String From, String Body) in C:\Users\rawatsid\Documents\BotConnectorAPI\Controllers\myBotConnectorController.cs:line 55
at lambda_method5(Closure, Object)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

If I'm not wrong, the above error points to the myBotConnectorController.cs file, at line 67:

    private async Task<string> StartConversation(string inputMsg, string token)
    {
        Console.WriteLine("token: " + token);
        using (var directLineClient = new DirectLineClient(token))
        {
            var conversation = await directLineClient.Conversations.StartConversationAsync();
            var conversationtId = conversation.ConversationId;//FAIL HERE

I'm unable to debug what could be the possible problem here. Any idea as to what might be causing this problem?

noufionline commented 1 year ago

I've experienced a similar problem, where the StartConversationAsync() method consistently returns null. The documentation suggests that the relayboat is now a legacy component, and it encourages the use of the Skill bot moving forward. However, integrating this with Twilio poses a challenge. Despite my efforts in contacting their support and opening two tickets, I've yet to receive a response. As we're both tackling the same issue, it might be beneficial for us to collaborate on finding a solution.

Screenshot 2023-05-05 at 9 30 04 AM
techakki81 commented 1 year ago

in my case the conversation null after a couple of times trying. For eg, if i start afresh on a new day it works for few tries and then goes null I suspect, it might be the case in case previous conversation is not fully completed ..ie the PVA does not reach the conversation end topic... but thats purely my guess

noufionline commented 1 year ago

In my case it didn't work at all. Would you mind sharing your code to compare what did I miss. I am also in contact with twilio support. lets see what they come up with

romeroej2 commented 1 year ago

Hi! i had the same issue. the issue is not the code, its the VPA instance. i swapped to a different tenant and it just worked.

sydrawat01 commented 1 year ago

Hi! i had the same issue. the issue is not the code, its the VPA instance. i swapped to a different tenant and it just worked.

I can confirm, I just changed the values in appsettings.json and it works just fine! Seems like a very weird bug tbh.

b06sd commented 10 months ago

Hi @sydrawat01 what did you change in your appsettings.json file? Currently experiencing this.

techakki81 commented 10 months ago

hi I was able to overcome this issue by using a PVA secret rather than token for authentication. I think its a bug in PVA

thanks a

Trisanganguly commented 9 months ago

Since you guys have solved the issue , can you guide what exactly needs to be provided in appsettings.json

38aytac38 commented 8 months ago

I have the same problem if I use a new PVA but if I use a Classic PVA it works.

Moriti-Ramolefo commented 4 months ago

Hi, I need help... Is there a way to run this bot connector api app on a european environment?

I read on MS that the default uri used is https://directline.botframework.com/ and the eu version is https://europe.directline.botframework.com/. Here's the link i read from https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-api-reference?view=azure-bot-service-4.0