Example of RTM Websocket (No SDK)

Hi

I am using bot enterprise on-premises and have a requirement to use RTM + Websockets on the server-side, i see the documentation below but details are vague, is there an example of simple send, receive user message.

https://developer.kore.ai/docs/bots/sdks/bots-platform-api-reference/

P.S : i don’t want to utilize KoreSDK as its using client-side browser-request and WebSockets

@sudheej
I am not sure why you want to use the RTM + WebSocket on the server and not our web channel but the process of communication using web-socket is explained at a high level remains the same, regardless of whether you use the websdk or implement a custom solution.

For using RTM and WebSocket, the mentioned URL gives you basic steps.
Step 1: First the authentication JWT is required. This will return an access token (JWT) using the client id, secret, anonymous and userIdentity.
Step2: Then /jwtgrant call will validate the JWT.
Step3: /rtm/start call will return the websocket URL. This URL has to be used to establish a connection.

There are few more things which our web-sdk does - like sending and receiving messages from WebSocket. You may study the same on our open-source sdk.

Example - https://github.com/Koredotcom/web-kore-sdk/blob/master/UI/chatWindow.js#L1888

You may also need to check how the websdk maintains webSocketConnection. example - https://github.com/Koredotcom/web-kore-sdk/blob/master/kore-bot-sdk-client.js#L1235

Since this is a custom requirement, if you have any SoW with our professional services team you will be better off.

Did you consider using our webhook channel for bot communication instead of creating a custom WebSocket solution?
https://developer.kore.ai/docs/bots/channel-enablement/adding-webhook-channel/

@srirama.yadlapalli @yogaramya.mendu

@swagata.sengupta Thank you for the response, i have usecase to connect with the bot from serverside, may be i am not using the correct sdk. Is there bot sdk available ?
All i am trying to do is to build an api that could send and receive message from the bot using node.

So far i’ve managed to use websdk and replace few of the dependenecies in kore-sdk js file such as replaced dom with jsdom, browser-request with request and ws with websocket (node library).

The bot is responding back to message[“type”] = “ping” with a pong response. However when i send a message i do get “internal server error” from the bot. I believe using web sdk is the wrong approach since the lib are client side.

@sudheej

For your use case when you want to use just an api to talk to the bot you can use webhook channel of a bot. It will ensure you do not have to do any websocket management like keeping it alive etc.
https://developer.kore.ai/docs/bots/channel-enablement/adding-webhook-channel/

Here is a sample webhook post-call

curl --location --request POST ‘https://bots.kore.ai/chatbot/hooks/st-59d03560-8722-5a69-b4c6-0904a0cde8a1
–header ‘Authorization: bearer eyJhbGXXXXXXXXXXXXXX.eyJzdWIiOiJrXXXXXXXXXXXXXXXXXXXXXXX.-8-haiFoGLVXXXXXXXXXXXXpA’
–header ‘Content-Type: application/json’
–data-raw '{
“session” :{
“new” : true
},
“message”:{
“text” : “webhooktest”
},
“from” :{
“id”: “a@b.com
},
“to” :{
“id”: “st-59d03560-8722-5a69-b4c6-0904a0cde8a1”

	},
    "customEmailId" : "zeetv@btv.com"

}