Call in sick with a custom bot for Hangouts Chat

Update your calendar and auto-responder with a single message to your custom bot.

Last updated: August, 2019

Description

When you wake up feeling ill the last thing you want to do is log in to your work account and update your status in multiple applications. With this solution, you simply send the message "I'm sick" to a custom bot in Hangouts Chat and it will turn on your out of office message in Gmail and block off your day in Google Calendar.

demo

Technology highlights

  • Uses the Hangouts Chat API to build a chat bot, which you can message just like a human participant.
  • The bot is implemented using [Apps Script][apps_script], allowing for rapid development and worry-free operation.
  • Uses the Gmail API to set the user's out-of-office auto-responder.
  • Blocks off the user's calendar using the Calendar API.

Try it

First, create the script:

  1. Click here to open the bot code in the Apps Script code editor.
  2. Click the menu item File > Make a copy to get your own copy. You can later access this copy in the G Suite Developer Hub.

Then create a Google Cloud project to use with it:

  1. Create a new project in the Google Cloud Developer Console. Name it "Call in Sick", select a Billing Account if prompted, and click CREATE. More information on how to setup billing here.
  2. When the project creation is complete a notification appears in the upper-right of the page. Click on the Create Project: Call in Sick entry to open the project.
  3. Open the OAuth consent screen settings page for the project.
  4. In the field Application name enter "Attendance Bot" and click the Save button at the bottom.
  5. Open the Gmail API page in the API library and click the ENABLE button.
  6. Open the Project settings page for the project.
  7. Copy the value listed under Project number.

Next, setup your script to use the new project and deploy it:

  1. Back in the Apps Script Code Editor, click the menu item Resources > Cloud Platform project.
  2. Enter the project number into the text box and click Set Project. When prompted, click Confirm.
  3. When complete, click the Close button or X icon to dismiss the dialog.
  4. Click the menu item Publish > Deploy from manifest.
  5. Next to the entry Latest Version (Head) click Get ID.
  6. Select and copy the Deployment ID value.
  7. Close the dialog and the Deployments window.

Then configure the Hangouts Chat API to create your bot:

  1. Back in the Google Cloud Developers Console, open the Hangouts Chat API page in the API library and click the ENABLE button.
  2. Once the API is enabled, on click the Configuration tab.
  3. In the Configuration tab, do the following:
    1. In the Bot name box, enter "Attendance Bot".
    2. In the Avatar URL box, enter https://goo.gl/kv2ENA.
    3. In the Description box, enter "Call in sick with a bot".
    4. Under Functionality, select Bot works in direct messages.
    5. Under Connection settings, select Apps Script project and paste your script's Deployment ID into the text box.
    6. Under Permissions, select Specific people and group in your domain. In the text box under the drop-down menu, enter your email address.
    7. Click Save changes.
  4. 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.

Finally, test that your bot is working:

  1. Open Hangouts Chat.
  2. Click Find people, rooms, bots > Message a bot.
  3. From the list, select the Attendance Bot that you created.
  4. Send the message "I'm sick" to the bot.
  5. Click the CONFIGURE button and authorize access to your account.
  6. In the resulting card, click the SET VACATION IN GMAIL and BLOCK OUT DAY IN CALENDAR buttons.

Next steps

To learn more about how the bot was made, follow this codelab for detailed instructions on each step in the process. You can also view the full source code of this solution on GitHub if you want to jump right to the end.

Feedback

Were you able to get the solution up and running?

If you have an idea for another solution you'd like to see featured in our gallery submit a request on the GitHub issue tracker.

Send feedback about...

G Suite Developer