Skip to content

Commit

Permalink
chore: Rebrand all Node samples to use App instead of Bot (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinay-google authored Jul 15, 2023
1 parent 786799c commit cbfa22b
Show file tree
Hide file tree
Showing 26 changed files with 114 additions and 114 deletions.
2 changes: 1 addition & 1 deletion node/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Hangouts Chat Node Samples
# Google Chat Node Samples

This directory contains various code samples written using Node.js.

Expand Down
52 changes: 26 additions & 26 deletions node/accounts-bot/README.md → node/accounts-app/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Accounts Bot
# Accounts App

This demo bot serves account owner information for a fictional sales team. This code sample
shows how create a bot that looks up information from a [Google Sheet][data_sheet] and served by a
[Google Cloud Function][gcf]. With this bot, a user who requests an account owner's information will
This demo app serves account owner information for a fictional sales team. This code sample
shows how create a app that looks up information from a [Google Sheet][data_sheet] and served by a
[Google Cloud Function][gcf]. With this app, a user who requests an account owner's information will
either receive a card with contact info or an option ensure the data is up-to-date if the requested
account could not be found.

![Acme-Lookup](https://github.com/googleworkspace/hangouts-chat-samples/blob/main/node/accounts-bot/assets/AcmeLookup.png)
![Acme-Lookup](https://github.com/googleworkspace/google-chat-samples/blob/main/node/accounts-app/assets/AcmeLookup.png)

[gcf]: https://cloud.google.com/functions
[data_sheet]: https://docs.google.com/spreadsheets/d/1kxW15ZI48mh4KkvgsMpg7gInmEQmyKYRnZdbUOSMRnU/copy

## Prerequisites

1. The [Google Cloud SDK][cloud_sdk] and `gcloud` set up on your machine.
1. Please be sure to have completed or understood the concepts in the Hangouts Chat
Google Cloud Functions [quickstart guide][gcf_bot] first.
1. Please be sure to have completed or understood the concepts in the Google Chat
Google Cloud Functions [quickstart guide][gcf_app] first.

[cloud_sdk]: https://cloud.google.com/deployment-manager/docs/step-by-step-guide/installation-and-setup
[gcf_bot]: https://developers.google.com/hangouts/chat/quickstart/gcf-bot
[gcf_app]: https://developers.google.com/google/chat/quickstart/gcf-app

## Set up instructions

Expand All @@ -35,15 +35,15 @@ Google Cloud Functions [quickstart guide][gcf_bot] first.
### Set up a Google Cloud Project (if needed)

1. [Create a new project][new_project] in the Google Cloud Developer Console.
Name it "AccountsBot", select a **Billing Account** if prompted, and
Name it "AccountsApp", select a **Billing Account** if prompted, and
click **CREATE**. More information on how to setup billing [here][billing].
1. When the project creation is complete a notification appears in the
upper-right of the page. Click on the **Create Project: AccountsBot** entry
upper-right of the page. Click on the **Create Project: AccountsApp** entry
to open the project.
1. Open the [**OAuth consent screen**][consent_screen] settings page for the
project.
1. In the field **Application name** enter "AccountsBot" and click the
**Save** button at the bottom.
1. In the field **Application name** enter "AccountsApp" and click the
**Save** button at the apptom.
1. Open the [**Sheets API**][library_sheets] page in the API library and click
the **ENABLE** button.
1. Open the [**Project settings**][project_settings] page for the project.
Expand All @@ -58,7 +58,7 @@ the **ENABLE** button.
### Deploying the Cloud Function

1. In your working directory, deploy the Cloud function with the following command:
`gcloud functions deploy accountsBot --runtime nodejs8 --trigger-http`
`gcloud functions deploy accountsApp --runtime nodejs8 --trigger-http`

### Set the permissions on the data

Expand All @@ -77,35 +77,35 @@ Service Account address which should be in this format:
[service_accounts]: https://console.cloud.google.com/iam-admin/serviceaccounts
[functions_iam]: https://cloud.google.com/functions/docs/concepts/iam

### Publish the bot to Hangouts Chat
### Publish the app to Google Chat

1. Back in the Cloud Console, open the
[**Hangouts Chat API**][library_chat] page in the API library and click the
[**Google Chat API**][library_chat] page in the API library and click the
**ENABLE** button.
1. Once the API is enabled, on click the **Configuration** tab.
1. In the Configuration tab, do the following:
1. In the **Bot name** box, enter "AccountsBot".
1. In the **App name** box, enter "AccountsApp".
1. In the **Avatar URL box**, enter `https://www.gstatic.com/images/icons/material/system_gm/1x/badge_black_18dp.png`.
1. In the **Description box**, enter "Easy account owners look up".
1. Under **Functionality**, select all options.
1. Under **Connection settings**, select **Bot Url** and paste
1. Under **Connection settings**, select **App Url** and paste
your the URL for the Cloud Function trigger into the box.
1. Under **Permissions**, select **Specific people and group in your
domain**. In the text box under the drop-down menu, enter your email
address.
1. Click Save changes.
1. After you save your changes, verify that the status on the Hangouts Chat API
page shows the Bot Status to be **LIVE – available to users**.
1. After you save your changes, verify that the status on the Google Chat API
page shows the App Status to be **LIVE – available to users**.

[library_chat]: https://console.cloud.google.com/apis/library/chat.googleapis.com

## Test the bot
## Test the app

1. Open [Hangouts Chat][hangouts_chat].
1. Click **Find people, rooms, bots > Message a bot**.
1. From the list, select the **AccountsBot** that you created.
1. Send the message "Acme" to the bot, you should receive a card shown above.
1. Open [Google Chat][google_chat].
1. Click **Find people, rooms, apps > Message a app**.
1. From the list, select the **AccountsApp** that you created.
1. Send the message "Acme" to the app, you should receive a card shown above.
1. Send the message "foo", you should receive the default card:
![Foo-Lookup](https://github.com/googleworkspace/hangouts-chat-samples/blob/main/node/accounts-bot/assets/FooLookup.png)
![Foo-Lookup](https://github.com/googleworkspace/google-chat-samples/blob/main/node/accounts-app/assets/FooLookup.png)

[hangouts_chat]: https://chat.google.com
[google_chat]: https://chat.google.com
File renamed without changes
File renamed without changes
4 changes: 2 additions & 2 deletions node/accounts-bot/index.js → node/accounts-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ACCOUNT_IMAGE_URL = 'https://www.gstatic.com/images/icons/material/system_
* @param {!express:Request} req HTTP request context.
* @param {!express:Response} res HTTP response context.
*/
exports.accountsBot = async (req, res) => {
exports.accountsApp = async (req, res) => {
const message = req.body.message;
if (!message || !message.text) {
console.log('invalid request');
Expand Down Expand Up @@ -63,7 +63,7 @@ async function getSheetsClient() {
}

/**
* Creates JSON response for a simple text message for Hangouts.
* Creates JSON response for a simple text message for Google Chat.
*
* @param {String} message the text of message response
* @return {JSON} the reponse data
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "accounts-bot",
"name": "accounts-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand Down
8 changes: 8 additions & 0 deletions node/avatar-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Cloud Functions avatar app

This code sample creates a simple Google Chat app that responds to
a simple message with the user's avatar.

## Run the sample in Google Chat

Please see [instructions](https://developers.google.com/chat/quickstart/gcf-app).
6 changes: 3 additions & 3 deletions node/avatar-bot/index.js → node/avatar-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

/**
* Google Cloud Function that responds to messages sent from a
* Hangouts Chat room.
* Google Chat room.
*
* @param {Object} req Request sent from Hangouts Chat room
* @param {Object} req Request sent from Google Chat room
* @param {Object} res Response to send back
*/
exports.helloChat = function helloChat(req, res) {
if (req.method === 'GET' || !req.body.message) {
res.send('Hello! This function is meant to be used in a Hangouts Chat ' +
res.send('Hello! This function is meant to be used in a Google Chat ' +
'Room.');
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node/avatar-bot/package.json → node/avatar-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "avatarbot",
"name": "avatar-app",
"version": "1.0.0",
"description": "A basic chatbot that returns the user's avatar image ",
"description": "A basic Google Chat app that returns the user's avatar image ",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
8 changes: 0 additions & 8 deletions node/avatar-bot/README.md

This file was deleted.

18 changes: 18 additions & 0 deletions node/basic-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Google Chat basic app

This code sample creates a simple Google Chat app that can responds to events and
messages from a room. This sample is built using NodeJS ( ExpressJS Framework ) on Standard Environment.

## Run the sample locally

1. Install libraries using `npm`. </br>
`npm install express body-parser --save` or </br> `npm install` (if package.json is available)
2. Run the sample.</br>
`node index.js`

## Configuring the url to Google Chat

1. To configure the app to respond to @ mentions in Google Chat, follow the steps to enable the API in [Publishing apps](https://developers.google.com/chat/how-tos/apps-publish).

2. When configuring the app on the **Configuration** tab on the
**Google Chat API** page, enter the URL for the deployed version of the app into the **app URL** text box.
12 changes: 6 additions & 6 deletions node/basic-bot/index.js → node/basic-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ const express = require('express');
const PORT = process.env.PORT || 9000;

const app = express()
.use(express.urlencoded({extended: false}))
.use(express.json());
.use(express.urlencoded({extended: false}))
.use(express.json());

app.post('/', (req, res) => {
let text = '';
// Case 1: When BOT was added to the ROOM
// Case 1: When App was added to the ROOM
if (req.body.type === 'ADDED_TO_SPACE' && req.body.space.type === 'ROOM') {
text = `Thanks for adding me to ${req.body.space.displayName}`;
// Case 2: When BOT was added to a DM
// Case 2: When App was added to a DM
} else if (req.body.type === 'ADDED_TO_SPACE' &&
req.body.space.type === 'DM') {
req.body.space.type === 'DM') {
text = `Thanks for adding me to a DM, ${req.body.user.displayName}`;
// Case 3: Texting the BOT
// Case 3: Texting the App
} else if (req.body.type === 'MESSAGE') {
text = `Your message : ${req.body.message.text}`;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node/basic-bot/package.json → node/basic-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "basic-bot",
"name": "basic-app",
"version": "1.0.0",
"description": "This is a basic bot to interact with Hangouts Chat",
"description": "This is a basic app to interact with Google Chat",
"main": "index.js",
"scripts": {
"start": "node index.js",
Expand Down
18 changes: 0 additions & 18 deletions node/basic-bot/README.md

This file was deleted.

18 changes: 9 additions & 9 deletions node/basic-cloud-functions-bot/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Cloud Functions Basic Chat bot
# Cloud Functions Basic Chat app

This code sample creates a simple Hangouts Chat bot that responds to events and
This code sample creates a simple Google Chat app that responds to events and
messages from a room. The sample is built using JavaScript on Google Cloud
Functions.


## Run the sample in Hangouts Chat
## Run the sample in Google Chat

1. Create a cloud function
`gcloud functions deploy basicBot --trigger-http`
2. [Enable the Hangouts Chat API, configure and publish the bot](https://developers.google.com/hangouts/chat/how-tos/bots-publish).
`gcloud functions deploy basicapp --trigger-http`
2. [Enable the Google Chat API, configure and publish the app](https://developers.google.com/chat/how-tos/apps-publish).
Make sure to register the URL for the App Engine instance as the
**HTTP endpoint** of the bot.
1. Add the bot to a room or direct message.
2. Send the message to the bot with an @-message or directly in a DM, example:
`@BotName i love dogs`
**HTTP endpoint** of the app.
1. Add the app to a room or direct message.
2. Send the message to the app with an @-message or directly in a DM, example:
`@AppName i love dogs`
30 changes: 15 additions & 15 deletions node/basic-cloud-functions-bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/

/**
* Description: A basic Chat Bot setup, to be used with Google Cloud Functions.
* Description: A basic Google Chat App setup, to be used with Google Cloud Functions.
*/

const BOT_NAME = 'Basicbot';
const APP_NAME = 'BasicApp';

exports.basicBot = (req, res) => {
exports.basicApp = (req, res) => {
switch (req.body.type) {
case 'ADDED_TO_SPACE':
res.send(handleAddToSpace(req.body));
Expand All @@ -35,7 +35,7 @@ exports.basicBot = (req, res) => {
};

/**
* Handles interactions when when the Bot is added to the Room.
* Handles interactions when when the App is added to the Room.
* @param {Object} body
* @return {Object} returns a Card with widgets containing key value pairs
*/
Expand Down Expand Up @@ -73,18 +73,18 @@ function handleCardClick(body) {
}

/**
* Removed bot name, extra spaces, and returns back the important part of the
* Removed App name, extra spaces, and returns back the important part of the
* text sent.
* @param {String} text
* @return {String}
*/
function cleanText(text) {
return text
.toLowerCase()
.replace(`@${BOT_NAME.toLowerCase()}`, '')
.split(' ')
.filter((char) => char !== '')
.join(' ');
.toLowerCase()
.replace(`@${APP_NAME.toLowerCase()}`, '')
.split(' ')
.filter((char) => char !== '')
.join(' ');
}

/**
Expand All @@ -103,7 +103,7 @@ function getInteractiveCard() {
title: 'Which type',
subtitle: 'Click on to Choose',
imageUrl:
'http://www.freepngimg.com/download/dog/9-dog-png-image-picture-download-dogs.png',
'http://www.freepngimg.com/download/dog/9-dog-png-image-picture-download-dogs.png',
imageStyle: 'IMAGE',
},
sections: [{
Expand Down Expand Up @@ -172,21 +172,21 @@ function getSingleImage(imageUrl) {
}

/**
* Returns a Card List Commands/Usage of the bot.
* Returns a Card List Commands/Usage of the App.
* @return {Object}
*/
function getHelp({user}) {
const commands = [
['Your First Command', `@${BOT_NAME} {command name}`],
['Interactive Command', `@${BOT_NAME} i love dogs`],
['Your First Command', `@${APP_NAME} {command name}`],
['Interactive Command', `@${APP_NAME} i love dogs`],
];
return {
cards: [{
header: {
title: `Need Help ${user.displayName}?`,
subtitle: 'Examples Below:',
imageUrl:
'https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/2000px-Google_%22G%22_Logo.svg.png',
'https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/2000px-Google_%22G%22_Logo.svg.png',
imageStyle: 'IMAGE',
},
sections: [{
Expand Down
Loading

0 comments on commit cbfa22b

Please sign in to comment.