This tutorial will go over how to build a bot that will respond to pings (i.e. @), and send messages to a chat room. On a high level, the bot will run on an express server, and receive pings via an HTTP endpoint. Responses to pings will be sent synchronously through a payload in the HTTP response, while bot-initiated messages will be sent asynchronously using the Google Hangout Chat API.
Create a new project with the file ‘app.js’.
Open command line/terminal, and navigate to your project directory. Run ‘npm init’, and press enter until package.json is created. Next, install the following dependencies:
npm install express --save
npm install body-parser --save
npm install googleapis --save
npm install unirest --save
In ‘app.js’, let’s setup our server:
const express = require('express');
const bodyParser = require('body-parser');
const { google } = require('googleapis');
const app = express();
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
app.listen(8100, function() {
console.log('App listening on port 8100.');
});
Running ‘node app.js’ will now create a local server on port 8100.
#express #nodejs #hangout #google