Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Webhooks example (node.js)

This example demonstrates how the webhooks feature can be used so that additional functionality can be added to your TalkJS enabled applications. For more information check out TalkJS.com or get in touch.

Installation

First start by cloning the example repository and changing the working directory to the project folder:

git clone https://github.com/talkjs/talkjs-examples.git
cd talkjs-examples/webhooks/nodejs/express-webhook

And lastly, install the required npm packages:

npm install

Initial setup

The example requires you to set your application ID in the a .env file. Visit the TalkJS dashboard and copy your development appId to the example.env file and then rename the file to '.env'.

Additionally, a secret key must be set to allow TalkJS's identity verification and webhook integrity features to work.

Optional: A port can be specified to override the default port (3000) that the application runs on.

The .env file should look similar to the following:

APPID=abc123
SECRET=secretvalue
PORT=3000

Getting started

Once the example has been installed and configured the application can be started using:

npm start

You should see something similar to this in the console:

console view

Once the application has started, copy the Webhook URL to the webhook setting in your TalkJS dashboard.

The application should now be temporarily accessible online by using ngrok, a tool used to temporarily create a tunnel between your local development app and a public URL so that TalkJS can send the webhook events to your local development environment.

Features

Inspect requests that are sent to the demo webhook endpoint by opening the Ngrok inspector (http://127.0.0.1:4040) once the application has started. Ngrok inspector

Trigger events using the demo UI - The example has a demo chat application to easily trigger events such as user.created, message.send and message.read. Demo UI example

Easily prototype event handlers - Event handlers can easily be prototyped, triggered and testing all without restarting the server due to live-reloading. A list of all the event handlers can be found on the webhooks section of the documentation

App Strcture

Important files ./app.js - The main application file which initiates express and sets the route-handlers and a middleware.

./routes/ - Contains two files used to seperate the routes from the main app.js.

./controllers/ - There are two controllers, one to handle the webhooks and one to display the demo chat UI.

./models - Contains a single mock User model

.env - Used to store environment variables for the demo application

./bin/www - Used to start the express.js server

./bin/ngrok - Used to create an Ngrok tunnel between the demo app and the internet

./views - Contains two views using the handlebars view engine:

  • chat.hbs - A single inbox view with the option to swap to another User's inbox (to trigger read notifications etc.)
  • dual-chat.hbs - Contains two inbx UI's, with different users for each one. This helps to demonstrate the real-time nature of TalkJS

Need help?

If you need help, check out the TalkJS documentation or feel free to talk with us or send us an email.