DEV Community

Cover image for Build a chat app with Twilio and KendoReact

Build a chat app with Twilio and KendoReact

Phil Nash on January 31, 2019

Twilio Programmable Chat provides an SDK and robust back-end for real time chat applications, but it's missing a front-end. If you need a chat UI, ...
Collapse
 
zeluspudding profile image
Andrew Agostini • Edited

Great article @phil Nas! I found your writing style a lot easier to follow than other coding tutorials. Kudos to your clean and concise flow.

I do have a question - Do we need to fill in the TWILIO_TWIML_APP_SID to get this tutorial to work? I did but I'm not sure what to set the Messaging Request URL to.

At any rate, I get an error that reads:

Proxy error: Could not proxy request /chat/token from localhost:3000 to http://127.0.0.1:3001.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).

It seems like the server at 127.0.0.1:3001 isn't starting but I'm not sure why. Any guesses?

Collapse
 
philnash profile image
Phil Nash

Thanks very much!

You do not need to fill in the TWILIO_TWIML_APP_SID env variable, you only need the TWILIO_ACCOUNT_SID, TWILIO_API_KEY, TWILIO_API_SECRET and TWILIO_CHAT_SERVICE_SID.

When you start the application, are you running npm run dev? That should start the front end on localhost:3000 and the server on localhost:3001.

Let me know if that helps.

Collapse
 
zeluspudding profile image
Andrew Agostini • Edited

Yes, I have been starting it with npm run dev. When that didn't work I tweaked the localhost:3001 proxy to be http://127.0.0.1:3001/ and several other variations (even switching up the port number) according to suggestions on Stackoverflow and github, but those tries didn't pan out either. I would share other error messages to help you help me but unfortunately all I get is what I already posted above.

I also tried standing this up using your completed code (per chance I fudged something between pastes) but couldn't get that to work either. That threw a different error but I'm unable to share that one until this evening when I'm back home.

Thread Thread
 
philnash profile image
Phil Nash

Hmm, this is weird. Let me know what error you're getting from the completed project and hopefully we can get that fixed.

Also, for the one you worked on from the article, can you try the individual commands npm run server to start the server and npm start to build the front end and see if that helps or shows you any more errors?

Thread Thread
 
zeluspudding profile image
Andrew Agostini • Edited

Hey, thanks for following up!

I just checked and got this error:
'run-p' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-express-starter@0.1.0 dev:
run-p server start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-express-starter@0.1.0 dev script.

Seems to be related to not having npm-run-all. However, when I tried installing that using npm install npm-run-all I got another error saying:
npm ERR! 404 Not Found - GET https://registry.npmjs.org/event-stream/-/event-stream-3.3.6.tgz
npm ERR! 404
npm ERR! 404 'event-stream@3.3.6' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'twilio-chat-kendo-react'

...So stuck.

In a nice turn of events, however, I discovered TalkJS and got it working between two codepens in about 5 minutes. So I might be tinkering with that more.

It really strikes me that Twilio doesn't provide chat UI elements... like Stripe does with credit card forms. I know you're team has released Twilio Flex but I can't help but feel that a standalone chat element could only do good to sell more Twilio (it's not like it would canabalize your market for Flex).

At any rate, thank you for looking into this with me. I really do appreciate it.

Thread Thread
 
philnash profile image
Phil Nash

Ah, ok! This is an issue I've updated on a bunch of other projects, but not got to this one yet. This broke because of event-stream was compromised and then got yanked from the registry.

I've pushed updates to the package.json, so you should be able to pull the latest and try again.

Thread Thread
 
zeluspudding profile image
Andrew Agostini

Very interesting and unfortunate about event-stream (I hadn't known). I'm excited to try you're updated app :)

Changing the topic a bit, do you know of a site for checking whether an npm package is compromised.. something like Have I Been Pwnd? I couldn't find one in 30 seconds of googling...

Thread Thread
 
philnash profile image
Phil Nash

Compromised packages tend to be removed as soon as npm finds out about it, so there's not much need for a service like that.

There are services for checking whether a package has a vulnerability in. You can run npm audit or use something like Snyk to achieve this.

Collapse
 
enriquemorenotent profile image
Enrique Moreno Tent

Cool article, well written and complete, even though for some reason I have not managed to build it using react hooks.

Collapse
 
philnash profile image
Phil Nash

This is a good point, I intend to update this with hooks at some point too. What's going wrong with hooks for you at the moment?

Collapse
 
enriquemorenotent profile image
Enrique Moreno Tent

For some reason, when "messageAdded" executes, the "messages" state appears as an empty array, making all the previous chat history disappear whenever I type a new message.

Could it be that ChatUI mutates the array? I have no idea why that happens. I spent hours trying to find out, but I couldnt.

Collapse
 
enriquemorenotent profile image
Enrique Moreno Tent • Edited

Here is my component ChatApp written with hooks

pastebin.com/uVekpL41

Thread Thread
 
philnash profile image
Phil Nash

I'll try to have a play with this today. The ChatUI really shouldn't mutate the array. Will see what I can find.