This repository contains the REST API running as a PubNub function that is required for the ChatEngine Framework to operate.
Documentation You can find the full docs on the documentation website.
To set up PubNub to host the ChatEngine Framework REST API on a PubNub Function, you must first set up a new PubNub App. The following outlines how to manually set up a PubNub ChatEngine Framework Application and Key.
- Navigate to PubNub's Portal, sign in, and select Create New App.
- Enter an App name (e.g.
ChatEngine Application
) and click Create. - Select the newly made App icon and navigate to the Demo Keyset.
- Update the following setting on the keyset:
Presence | on |
---|---|
Announce Max | 20 |
Interval | 10 |
Presence Deltas | Disabled |
Generate Leave on TCP FIN or FIN | Disabled |
Global Here Now | Enabled |
Debounce | 2 |
Callback State Change | https://pubsub.pubnub.com/v1/blocks/sub-key/ __SUB_KEY__/chat-engine-server?route=user_state |
Storage & Playback | on |
---|---|
Retention | 7 days |
Stream Controllers | on |
---|---|
Enable Wildcard Subscribe | Enabled |
PubNub Functions | Enabled |
---|
Access Manager | Enabled |
---|
The REST API is composed of several files to improve understandability. The files must be bundled into a single function to upload to PubNub.
- Clone the
chat-engine-server
repo and runnpm install
. - Run
npm run build
to create a bundled function atbuild/server.js
. - Run
npm test
to verify that the bundle is correct. - Copy the code to your clipboard for later use.
-
On your PubNub Admin Dashboard, go the ChatEngine app key you set up in the previous section to upload your Function.
-
Select the Functions tab on the top left side of the page.
-
Fill out the following text fields and click Create New Module:
Field Value Module Name: ChatEngine Server
Module Description: REST Function that powers PubNub ChatEngine
-
Within the ChatEngine Module, click create and fill in the following text fields:
Field Value Function Name ChatEngine Server
Select Event Type On Request
URI path chat-engine-server
-
Click Create Function to navigate to the PubNub Functions Console.
-
With the console open, copy and paste the server code from
build/server.js
into the console editor and click Save. -
Click Save at the top left side of the console editor.
-
Click My Secrets, and enter the following, (get the
secretKey
from the App and Key page):Field Value Enter Key secretKey
Enter Value __COPY_AND_PASTE_PUBNUB_SECRET_KEY__
-
Click Save.
-
Returning to the console, click Start Function and you are done.
For more information on build chat applications with PubNub, see our Chat Resource Center.