Skip to main content

Building your first Google Hangouts Chatbot in Apps Script

Learning to build chatbots, with all the available approaches and technologies, can seem daunting. Similarly, building Google Hangouts chatbots can require some early decisions on server architectures, technical implementations, and even programming languages. You could, for example, build Google Hangouts chatbots using a variety of different technologies including Cloud Functions, HTTP web services, Cloud Pub/Sub, and Webhooks, to name a few. 
Fortunately for those who are in the early stages of learning to build bots for Google Hangouts, the “low code” Google Apps Script environment provides an easy path to get started. Also, because Apps Script offers native G Suite integration (including authentication), it can be the most pragmatic choice for building G Suite-centric chatbots on Google Hangouts.
Here’s a step-by-step guide on how to build your first Google Hangouts chatbot using Apps Script.

What is Apps Script?

Apps Script is a cloud-based scripting language and runtime environment based on JavaScript. It offers direct code access to a variety of Google products and APIs via its extensive library of services.
Apps Script is typically used to enhance the functionality of G Suite products (Google Sheets, Docs, Slides, Drive, and Gmail) by offering a streamlined “low code” approach. For example, to send an email in Apps Script, you can simply use:
MailApp.SendMail(“”,“My Subject”,“Hello from Apps Script!”);
Apps Script code development can also be done entirely in a browser, so there’s no need to install a local software development environment (for more on Apps Script, check out this Apps Script Overview).


Before diving in to this guide, please make sure you meet the following prerequisites:
  • You can create projects on Google Cloud Platform (GCP).
  • You’ve got a basic familiarity with Apps Script and/or JavaScript.
  • You’ve got G Suite Admin authority (you’ll need this for domain-wide publishing—for the simple testing described in this walkthrough, however, G Suite Admin authority isn’t needed)..

Now that you’re ready to get started, here are the basic steps to build and test your own chatbot in Apps Script.

Step 1: Create and configure your Apps Script project

Go to, click the “Create Project” button, name your project “Hello ChatBot”, click Save.
To configure the project for Chat:
  •  Access the Apps Script project’s Manifest file. View -> Show Manifest File
  • This opens the file appsscript.json (manifest) file in the script editor. You can now customize this file.
  • To add chat capabilities to this project, simply add  ”chat”: { }  to the manifest. For example:

  "timeZone": "America/Los_Angeles",
  "dependencies": {
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "chat": { }
  • Save the project.
  • In the file, add the following function to handle the incoming chat message:

  function onMessage(event) {
  var response = 'Hello, ' + event.user.displayName + 
    '!\nYou entered: \"' + event.message.text + '\".'; 
  return { "text": response };
  • Save the project.
That’s all the Apps Script code needed to run the chatbot! 

Step 2: Saving your deployment ID 

Our next steps are to associate the bot’s Apps Script project with a GCP project by getting the  Apps Script project’s Deployment ID and saving it for later when configuring a GCP project.
To get a deployment ID from the Manifest:
  • Publish > Deploy from manifest.
  • In the Deployments dialog box next to Latest Version (HEAD), click Get ID.
  • In the Deployment ID dialog box, copy the value listed for the deployment ID. It will look something like: AKfycbyS1N2v-_ZVNldWGBuY4azxodbOE06PTJGXKBU9hV3m
  • Copy and save the Deployment ID for later.
  • Click Close and Close to dismiss the dialog boxes.

Step 3: Create and configure your GCP Project 

Here, you’ll create and configure your GCP project so that it can serve as the chatbot backend.
To create a new GCP project: 
  • Goto and create a “New Project” (you can name it “My First Chatbot”).
  • Select your associated Billing account.
  • Accept the defaults for Organization and Location.
  • Click CREATE, and then select the new project in the console.
Next, you need to enable the Chat API in the project
  • From the main GCP Dashboard, click “goto APIs overview” to open the “APIs and Services” Dashboard.
  • Click:

  • Search for ‘‘Hangouts Chat API”. 
  • Once located, click ENABLE.


  • For your service account name, enter: “My First ChatBot Service Account.” An account id will be generated automatically (my-first-chat-bot-service-accou).
  • You can also add a service account description, but this is optional.
  • Click CREATE.
  • After the account is created, look for the “Service account permissions” section, and, in the Role dropdown menu, select Project -> Owner.

  • Click CONTINUE and DONE.
Finally, you’ll need to configure the Chat API. Click Configuration in the menu on the left, and add the following options:
  • Bot name: enter “My First Bot”.
  • Avatar URL: can provide your own publicly accessible image here if you want)
  • Description: ‘A simple first Hello Bot'.
  • Functionality: select Bot works in direct messages.
  • Connection settings: select Apps Script project and paste the Deployment ID from the Apps Script project into the field.
Under Permissions, select Specific people and groups in your domain, and enter your own email (from within the G Suite domain). Then click SAVE. Note that the SAVE button will remain active after saving, but the Bot status at the top of the page will change to “LIVE - available to users.”


Step 4: Test your new bot!

  • In a new browser window, open in the same domain and user specified as a chatbot user that you specified in the previous step.
  • Next to BOTS, click + to add your new bot. Search for your new bot.

  • Once located, click Add (and Message) to start a chat session with the new bot.
  • Enter “Hello!” and see the response!

  • Bonus step! Now that your bot is working, go back to the Apps Script code and add a change to the code so that it translates the message to French. 
    Hint, use: LanguageApp.translate(event.message.text,'en','fr')
  • As you save the project, you’ll notice that you can immediately test the bot with your latest code.


Popular posts from this blog

Set start times and import reminders in Tasks

Here comes one of the most awaited features. Tasks is one of the goals to follow what you have to do in G Suite. These new updates will help ensure the majority of your to-dos are in Tasks, and guarantee that you can monitor the due dates related with them. Moreover, importing reminders to Tasks can support your users if your association is at present changing from Inbox to Gmail.
Set a date and time for your tasks and receive notifications - You’ll find a place to add date & time. Create repeating tasks - Also you can make an event recur.

Import reminders into Tasks
This import tool will pull your reminders (from Inbox/Gmail, Calendar, or the Assistant) into Tasks.When importing reminders into Tasks, we’ll copy over the title, date, time and recurrence of the reminder. Please note, reminders with locations associated will not be imported. Additionally, this is a one-time import and not a constant sync.
- When you open Tasks on the web or your mobile app, you’ll see a prompt to cop…

Use Vault for Gmail Confidential Messages and Jamboard Files

Google vault will be supporting two new formats in the future, Gmail confidential mode emails & Jamboard files stored in Google Drive.
Google Vault gives you a chance to retain, hold, search, and export data to support your organization’s retention and eDiscovery needs. This dispatch includes support for new information types with the goal that you can thoroughly oversee your association's information.
What happens when individuals in your association sends confidential messages? Vault can hold, retain, search, and export all confidential mode messages sent by users in your association. Messages are constantly accessible to Vault, notwithstanding when the sender sets a termination date or denies access to private messages.
Here’s an example of what will see in Vault when they search for and preview this email sent by
But It’ll not work vise versa. Admins can hold, retain, search and export message headers and subjects of external c…

Save time with new scheduling features in Calendar

Save time with this new update. It allows you to schedule meetings easily.
Peek at calendars and automatically add guests - when you add a calendar in “search for people” box on the left hand side panel you can temporarily view coworkers’ calendars. Also at the same time those coworkers will be added automatically when creating an event.
More fields in the creation pop-up dialog - The Guests, Rooms, Location, Conferencing, and Description fields are currently editable  in the meeting creation popup dialog. When you include your colleagues' calendar, they'll load right in the background, making it much simpler and quicker to locate an accessible time for everybody. 

Follow us on -

Our Website - Our Facebook page -
Our LinkedIn page - Talk to our experts - 071 0326326