Sample Chat Web Server Applicat

by tigerfarm

GitHub Readme.md

PHP Chat Web Application

This application is ready to run. You will need a web server that can serve static files and run PHP programs.

To deploy to Heroku, an internet cloud service provider, you will need an Heroku account to host your application. Once you have an account, stay logged in for the deployment and configuration.

Deploy to Heroku

When you deploy to Heroku, you will be prompted for an app name. The name needs to be unique. Example, enter your name+app (example: davidapp). Click Deploy app. You will be prompted for the following environment variables:

  • ACCOUNT_SID : your Twilio account SID (starts with "AC", available from Twilio Console)
  • CHAT_SERVICE_SID : your Chat service SID. To create a Chat Service (CHAT_SERVICE_SID), click here.
  • CHAT_API_KEY : your Chat API key. To create an API key and secret string, click here.
  • CHAT_API_KEY_SECRET : your Chat API key secret

Note, you can manage the environment variables from the Heroku dashboard project Settings, by clicking Reveal Config Vars.

Chat Client Application screen print:

Requirements:

  • Twilio account. A free Trial account will work.
  • To run locally on your computer using the include web server, install Node.JS and the Twilio Node.JS helper library.

PHP Application Files

Heroku Deploying Files

  • webserver.js : For localhost testing, a NodeJS Express HTTP Server that serves the Chat client files.
  • app.json : Heroku deployment file to describe the application.
  • package.json : Heroku deployment file which sets the programming language used.

Node Webserver for localhost testing

  • webserver.js : For localhost testing, a NodeJS Express HTTP Server that serves the Chat client files.

For Developers

Following are the steps to run the Chat Web Application on your localhost computer.

Download this repository's zip into a working directory and unzip it. Create an environment variable that is your Twilio Function Runtime Domain. Example:

$ export ACCOUNT_SID ACxxx...xxx
$ export CHAT_SERVICE_SID ISxxx...xxx
$ export CHAT_API_KEY SKxxx...xxx
$ export CHAT_API_KEY_SECRET xxx...xxx

Run the Node.JS server program, install the required packages, then run the chat server or command line program.

$ npm install twilio
$ npm install twilio-chat
$ npm install express

$ node webserver.js

Test the Chat Web Server

Use your browser to run the chat client:
http://localhost:8000
Enter a username, example: stacy.
Enter a Channel name and description, example: "mychannel" and "My test channel".

In another browser tab, run another chat client using a , same channel name:
http://localhost:8000
Enter a username, example: david (different username).
Enter a Channel name, example: mychannel (same as the other client).

Send messages between your clients.

Cheers...