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

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 s

Zoom’s Work Transformation Summit on Jan. 19: Fresh Approaches for Moving Forward

These past two years have undoubtedly reshaped work. More specifically, these past two years — shuffling between remote, in-person, and hybrid work scenarios — reshaped what employees expect out of their jobs, how they want to work, and what the office means to them.  Organizations are challenged with making big decisions to meet those expectations, and those decisions will dramatically alter how they hire, manage their facilities, buy technology, and maintain productivity. Simply adjusting policies and retooling previous work models won’t do. It takes a comprehensive reimagining. To help organizations navigate this next phase of work, Zoom is hosting our  Work Transformation Summit  on Jan. 19, a free, half-day virtual event designed to provide you and your organization with meaningful strategies, creative approaches, and innovative solutions for redefining work.  Summit attendees will have the opportunity to hear from peers and industry experts on the importance of embracing technolo

Access well-known educational technology tools straight from Google Classroom.

  We're making it simpler for instructors to use popular EdTech products that are most effective for their class right in Google Classroom with a new seamless integration of single sign-on, assigning, and grading. With the help of this feature, teachers can find, assign, and grade interesting content for their classes, and both teachers and students can access their EdTech tools without needing to navigate to other websites or apps or go through a cumbersome login process that requires remembering numerous usernames and passwords. This offers a more simplified experience when using technology to affect learning, in addition to saving instructors and students time. We partnered with 15+ EdTech companies to build custom add-ons, including Kahoot!, Pear Deck, IXL, and Nearpod.  Admins :  In order for educators to use add-ons, district administrators must provide access to them. For further information on how to install the add-ons functionality and specific add-ons for a domain, OU, o