Follow this README to build your forum chat room with the help of PubNub ChatEngine and AWS Comprehend. This forum chat room provides the functionality of a chat room with the ability to suggest topics based on locations.
This repository contains the demo application for this forum chat room, along with a simulated chat session between a group of users. The source code for this chat app is in Javascript. Some level of familiarity with NodeJS, JQuery and standard Javascript language is expected.
For reference, you can check the documentation of PubNub Chat Engine, PubNub Functions and AWS Comprehend, which are the main components of this app.
Here is how the simulated chat session runs. It is depicting a public health advisory chat room about Zika Virus, and it generates "HeatTags" for all the locations mentioned in the chat messages. This indirectly indicates the impact and spread of Zika Virus in those locations.
You can follow the sections below to build this example chat app in no time. However, before you begin, you must have an account in PubNub and AWS.
Create your PubNub developer account
Create your free AWS account
First, you need to set up the ChatEngine enabled PubNub app in your account.
Step 1 : Login to your PubNub App Console
Follow these steps in ChatEngine QuickStart Tutorial to set up your chat app instance. Check the first step "Configure Your Account" in quickstart tutorial and click on the setup button.
Step 3 : Wait for a few seconds. Once done, you will get a new PubNub app created within your account with a new set of publish and subscribe keys.
Now your app infrastucture is created. Head over to the next section for setting up AWS Comprehend.
Follow these steps to setup your AWS Comprehend service
Follow these steps to create an IAM user for AWS Comprehend. Make sure that the IAM user has full permissions for accessing AWS Comprehend service.
Download the credentials file for the IAM user and save it. This file contains the AWS ACCESS KEY and AWS SECRET KEY.
Follow these steps to setup PubNub Function to serve as the backend for the forum chat app.
Head over to your PubNub dashboard and select the "ChatEngine App" app. Follow the official document of PubNub Function to create a function for this app by clicking on the "Functions" menu on the sidebar.
Create a new module within the functions tab by using the following parameters as mentioned in the form.
Enter a module name : Amazon Comprehend
Enter a module description : Use natural language classification to find locations in text
Which keyset should this module go under? : ChatEngine keyset
Under the module, create a new PubNub function by using the following parameters as mentioned in the form.
Function Name : Amazon Comprehend
Select an event type : Before Publish of Fire
Once done, you will have two modules. First one is created by default as part of ChatEngine App and the new one is created in this step.
Copy the AWS Comprehend backend code and paste it in the code window of the newly created PubNub function in previous step.
Add your AWS ACCESS KEY and AWS SECRET KEY (Step 2 of "Set Up AWS Comprehend Service") in the My Secrets vault as shown below.
Now start both the modules within the functions tab.
Follow these steps to test the app on your computer. NodeJS environment must be available to run this app.
Clone this repository under a local folder
Update the chat UI's PubNub publish key here and PubNub subscribe key here
There are five dummy users defined for the simulated session of this app. These users are represented by their individual NodeJS scripts.
For the moderator, update the PubNub Publish and Subscribe Keys at line 18 & 19 of the script file.
For the remaining users, update the PubNub Publish and Subscribe Keys at line 6 & 7 of the respective user's script file.
Now you are ready to launch the app instance. Before launching the app make sure that the AWS Comprehend PubNub Function is running.
To launch the chat room UI, you can open the chat room HTML file in a browser. Once you do that you will notice that the user named "Peter" has joined the chat. This is the human user which participates in the chat.
To launch the simulation, start the moderator bot under the NodeJS environment.
node app.js
CAUTION : Before launching the above command for the first time, make sure the install the node module dependencies
npm install
Have fun!