Skip to main content
artiem51422106
Known Participant
May 17, 2022 1:36 PM UTC
Question

Coldfusion send to a websoket from API (CFML Script)

I am hoping someone can point me in the right direction. I have a CF2021 Server which runs a Node.js websocket server and CF pages (via javascript) as a client. Messages from user to user work as expected, so no issue there.

This CF Server also has a custom API built using CFML that handles and routes inbound SMS messages. My question is; what would be the best way to send the SMS message (by now its json) to the Node.js websocket to it can send it to the user(s).

I tried using the same javascript that the browser client uses, but it appears that the CFML API script is "browser-less", so that doesn't work, or should it?

I thought something like Apache Groovy may be the solution, but I am having difficulties with any websocket broadcast example I have found.

Any suggestions would be greatly appreciated.

thanks in advance

    This topic is closed to new replies. Start a new post to keep the conversation going.

    3 replies

    BKBK
    Community Expert
    Community Expert
    May 17, 2022 3:22 PM UTC
    Messages from user to user work as expected, so no issue there.

    By @artiem51422106

    If I were you I would then find a way to make the CFML API emulate a user. Perhaps cfclient might be handy for converting CFML to Javascript. 

     

    Apache Groovy, like CFML, is server-side. So, were you to use Groovy, I would expect you to face the same challenges as you do with CFML.

     

    Translate
    artiem51422106
    Known Participant
    May 17, 2022 8:43 PM UTC

    BKBK,

     

    thanks for your reply, this has been days of trial an error. I looked into CFCLIENT and tried a few things, but I wasn't getting very far. I am most likely not doing it correctly, but it does not seem to load the jquery module which is needed to make the websocket connection within the CFCLIENT tag.

    I thought I was getting somewhere with the groovy code, as I was able to implement some groovy code (java) during the CFML template process on the server, but could no get any websocket code to run without errors, but I suspect that may be due to how I am invoking the groovy file.

    To my client - this should be an easy thing to do - CFML templates do the API processing and at some point, send a JSON structure to the running node.js websocket running on the same server. Finding a way to "emulate a websocket user" seems to be the whole issue unfortunately. Thanks again for your response.

    Translate
    BKBK
    Community Expert
    Community Expert
    May 18, 2022 1:28 PM UTC

    If the Javacript way is not feasible, there is yet another possibility. You could try creating a websocket object in ColdFusion, and using it to subscribe to a websocket channel on Node JS. Under the covers, ColdFusion would then convert the object into Javascript anyway. 

    Translate