Search code examples
twiliotwilio-apitwilio-programmable-chattwilio-conversationstwiliosms

Twilio Conversation API integration in .net web application


We have two different web applications, one application is developed in .Net core MVC technology and another application is developed in classic asp.net technology. We want to add live chat functionality between the above two applications users. How should we proceed to integrate chat API in application? Also share similar code example.

We are trying to use twilio conversation API however we are not able to find out the proper documentation.


Solution

  • Chat requires the Conversations Client Javascript SDK as covered in the Twilio Conversations documentation:

    When you build your solutions with Twilio Conversations, you need a Conversations Client Javascript SDK that runs in your end user’s web browser.

    To use Twilio for chat you will need to install and setup the Conversations Client Javascript SDK which will run in the browser. You will then need to coordinate the browser events with your server/controller events. The link above includes code which requires also installing and running Node.

    As an alternative to the Twilio javascript clients, I use Azure SignalR to in combination with Twilio Webhooks. Twilio sends webhooks when various events occurr. A server app listens for the webhooks and relays to Azure SignalR. The client (the web-page the end-user is browsing) uses the SignalR client to receive and act upon the SignalR messages. I have done this using Azure Functions, .NET MVC, and Blazor. Behind the scenes the Twilio javascript client is creating a websocket with a similar overhead (delay/latency) as SignalR. The reason I chose to do this was to use other benefits of SignalR and how it integrates with .NET for real-time communication (plus avoiding Javascript).

    The downside to the SignalR approach is having to write methods that essentially recreate the functionality of the Twilio javascript SDKs (i.e. writing an method that sends a chat message or dials a phone number).

    This is in no-way to imply that the Javascript SDKs are not helpful - they are fine and the Rest API is powerful. If the Javascript SDK meets your needs then it is almost plug-and-play to setup and use.