Twilio Programmable Chat WebSocket connection - node.js

I am working to integrate Twilio Programmable Chat into a Qt/QML application - meaning I cannot readily use the Javascript Client SDK. I would like to have features like typing indicator, token expiration notices, etc. handled in my client.
In the examples, the client sdk initiates a WebSocket connection directly to Twilio and receives events like token expiration, etc. directly.
Twilio seems to provide a number of SDKs that abstract the majority of features (read receipt, typing indicator, access-token), for Javascript, iOs, and Android.
However, it appears that their "server-side" wrappers (helper libraries) offer limited functionality only for accessing REST aspects of API, and not WebSockets.
As I am working in QML I cannot just drop a remote Javascript library into a webpage and start building a client (The Javascript inevitably does not act the same).
Does Twilio provide any documentation for access it's Programmable Chat WebSocket connections directly? I could also build my own NodeJS WebSocket wrapper around a library, however, twilio-node just looks like a wrapper around the REST API as well.

Twilio developer evangelist here.
The websocket API is not a documented API or protocol and it is not recommended to build against it as undocumented changes may break your implementation.
It is true that the server side libraries only cover the REST API. You can also receive events from the Chat API using the webhooks that are available.

Related

Why one need to implement web-hooks if pusher are working well?

Why one need to implement webhooks if pusher are working well?
Are web-hooks and pusher are interchangeable or web-hooks better than pusher
Are web-hooks and pusher are interchangeable
No, they are different technologies and have different use cases
or web-hooks better than pusher
They are not interchangeable and cannot be compared in this fashion.
Web Hooks are a standardised way for a service to send a message to another service/api using regular HTTPS calls and have to be registered on the sender's side.
Looking at Pusher, though seems to be an service providing the ability to provide push notifications to web browsers and apps.
UPDATE Just noticed that Pusher does appear to offer web hook integration as well for Pusher related events.

Implementing push notification using AWS lambda

I am referring to the diagram
NodeJS is used as run time in this case and AWS Lambda is used as event notifier (updates comes from other lambda or DB).
My challenge is, the "user browser" can also be a mobile client. The "API" should acts as a service which allows client (mobile or web) to subscribe, unsubscribe, or publish data, nothing else.
Can lambda works as API that has capabilities of "pushing events notifications" to directly clients?
Is there any solution and also sample work/source code can be used as POC?
Next question is, how can I scale such architecture since it becomes stateful (requires memory to remember states of clients connections)?
Or else, how possible is it persist client connections on DB (using frameworks like websocket or socket.io)?
AWS has the SNS service to send notifications, which you can use from Lambda.
You can also directly use the relevant platform's notification system e.g for iOS, Node has an "apn" module that is used to communicate with Apple's APNS service - it's straightforward to use and can be implemented in a Lambda function.
In brief:
Your iOS app registers for APNS which responds with an APNS device token. Your app should then send this to your API / server for storage.
Your API can then send notifications to APNS, referencing any device tokens, along with the private key file you create from the Apple Developer page.
APNS will send the notifications to the registered devices.
Here is a good tutorial.
Your other queries should perhaps be separate questions.
Can lambda works as API that has capabilities of "pushing events notifications" to directly clients?
Yes! As #AndyOS mentioned, SNS is a great service that is quite literally intended to send notifications. I won't go into details here to avoid duplication of response.
Is there any solution and also sample work/source code can be used as POC?
Or else, how possible is it persist client connections on DB (using frameworks like websocket or socket.io)?
If you are looking to use websockets, I'd encourage you to take a look at IoT (https://aws.amazon.com/iot). IoT supports the MQTT protocol (http://docs.aws.amazon.com/iot/latest/developerguide/protocols.html). This page also contains sample client-side code which might help you bootstrap your solution.
Next question is, how can I scale such architecture since it becomes stateful (requires memory to remember states of clients connections)?
You can view the service limits of IoT at http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html#limits_iot. You would need to decide if your app fits within these bounds, depending on the various metrics your app has (number of requests per second, number of concurrent connections, etc.).

instant messaging for apps

I'm developing a web and mobile app using spring mvc and I'm having a problem understanding the different protocols and tools to make instant messaging (like facebook messaging in the website or whatsapp instant notifications). one functionality besides chatting in the project is for a user to send a request and waiting for the other user to respond with notifying them instantly).
However I'm lost cause some say to use GCM or FCM for the mobile and others say there other protocols like STOMP and AQMP and some others. I don't know what to see and use in my rest api so that it works for both browsers and mobiles while taking performance and other issues into consideration and how to consume these messages from client (I mean does the consumption method varies based on the chosen protocol?). should I use multiple protocols and tools based on the source of the request (i.e. if mobile and Android --> GCM or FCM, if browser STOMP for example, if iOS --> don't know what to use).
I know it looks like a general question but I really got lost specially that I don't know what are the right things to choose these days to start with.
Messaging stack consists of multiple components. One of them is message transport - used to pas messages between the server and the client. FCM/GCM/APNS in this context is the transport protocol.
GCM is deprecated in favor of FCM. FCM is going to work for Android, the latest versions of iOS, and even some browsers. However if the user disables notifications for your app, the messaging will stop working. There is also some unpredictable latency with push notifications, particularly if you would like to send high-volume messages like typing notifications.
Message format is another component of the stack. For instance, STOMP is the message format protocol. It's defined for any serial transport, i.e. can be used over FCM or TCP or websocket.
Given the questions you ask it looks completely impractical for you to write your own messaging stack. Just pick something off the shelf, like one of the million XMPP servers or a more modern one like Tinode. Google it.

How to use recording feature using Twilio Client (VoIP)

I am using Twilio Client (VoIP) with nodejs for making a call from my device to a phone.
I want a recording functionality also with this but I don't see this API supports it.I see rest API which supports this but then it not supports VOIP.
can someone please provide a sample code or any help for this.
very sorry for a silly question but I am new to programming.
Thanks in advance.
The JavaScript Client is actually not making the recording but the TwiML does. You setup your device and establish a connection to Twilio. Audio from your device's microphone is sent to Twilio, and Twilio plays audio through your device's speakers, like on a normal phone call.
This is analogous to the way Twilio handles incoming calls from a real phone. All the same TwiML verbs and nouns that are available for handling Twilio Voice calls are also available for handling Twilio Client connections.
So assuming that you are calling a customer's number and want to record the call, you will need to pass this instruction in the TwiML, i.e:
<Response><Dial record=true>[Number to call]</Dial></Response>
Or in node.js:
resp.dial({
record:'true'
});
After the recording is complete, it gets assigned a recording SID just like recordings created via the verb, and you can fetch it via the REST API as documented here:
https://www.twilio.com/docs/api/rest/recording#list

Connect node.js and signalr via sockets

Is there anyway to send data though sockets from Node.JS to SignalR? I have a Node.JS app that sends realtime information as JSON format. The other app it's an MVC C# app that uses SignalR to send the data to the client via socket. I want tosen data from de nodejs to signalr and signal send that info to the client.
You might consider better solution for internal communication between processes. SignalR is meant to be used between .Net server and client using different authentication, handshake, protocol and network layer methods, which is inefficient for internal server communication.
Take a look on ZeroMQ, is well simple and very easy to use tool, meant especially for such cases. It has bindings for most languages including .Net and node.js.
There is js client for browser to communicate with Signal R server.
http://www.nuget.org/packages/SignalR.Js
You probably can extract js file from it and run from Node.js.
And probably standard Socket.IO will just work, you need to subscribe to proper events and go.
If you want a node.js client for signalR that doesn't require jQuery I started this one. It intentionally only supports websockets.
https://npmjs.org/package/signalr-client

Resources