Community Keijiban is an experiment that explores how voice and the Assistant can make technology more accessible for new audiences. The Yamayuri Club of Wakabadai collaborated with us and friends at the Google Creative Lab to design a voice app that simplifies the lives of the people in the residential estate by bringing the community notice board to their living room. The app announces all new notices, tells the residents what activities are scheduled and reminds them when it's time to attend.
Anyone can customise the app for their local community by getting the code to build their own community management tool from scratch, controlled by Google Sheets.
This is an experiment, not an official Toaster or Google product. We will do our best to support and maintain this experiment but your results may vary.
Community Keijiban is built on Actions on Google, the platform that allows you to make things for the Google Assistant/Home. It uses Dialogflow to handle understanding what the user says, Firebase Cloud Functions and Firebase Realtime Database for backend code and storing data. It uses Google App Scripts to share the schedule from Google Sheets to Firebase, Cloud Text-to-Speech to create the custom user blurts for notifications and Arduino for programming the electronics.
This repo contains everything you need to create your own community noticeboard. We won't go into all the details but you can explore the source code of each part to learn how it all works together. The below instructions allow you to build your own community management tool from scratch.
- Clone this repo
- Make a copy of this sheet
- Go to Firebase and login.
- If you don't have an account it's free to sign up and use.
- In Firebase Console add a new project
- Give it a name e.g. Community Keijiban
- Select your locations and agree to the T&Cs
- Press
Create project
thenContinue
once its created
- Go to
Develop > Storage
and pressGet Started
and follow the prompt. - In
Storage
create a folder calledaudio
- Then go to the
rules
tab and replace the current rules to allow public reads, using the below code (PressPublish
to save):service firebase.storage { match /b/{bucket}/o { match /{allPaths=**} { allow write: if request.auth != null; allow read; } } }
- Go to
Develop > Database
, scroll down the page and findOr choose Realtime Database
and clickCreate Database
and then clickenable
- Now go to your
⚙︎ > Project Settings > General
in Firebase - Make a note of your
Project ID
- Then go to your
⚙︎ > Project Settings > Service Accounts
in Firebase and selectDatabase secrets
- Then press
show
and make a note of yourDatabase secret
- Open the sheet you copied.
- Go to
Tools > Script Editor
- Inside Script Editor select the file
Code.gs
and replace the following values:[PROJECT-ID]
with yourProject ID
FIREBASE_DATABASE_SECRET
with yourDatabase secret
- Save the changes
- Go to
File > Project Properties > Info
and make a note of theProject key
- Close the Script Editor
- Refresh the Google Sheet
- Download and install Firebase CLI. Once you have completed step 4 under "Install the Firebase CLI" continue with the below steps.
- You need to initialize a new Firebase project, run the following command from within your project's directory
firebase init
and follow the on screen intructions. For most options you can use the defaults except for the below:- Select
Functions
andHosting
- Select the project name you created via the Firebase Console e.g.
Community Keijiban
- If your project name is not listed select
create a new project
and afterfirebase init
has completed you can usefirebase use --add
to add your project name
- If your project name is not listed select
- Select
JavaScript
for theFunctions
language - Say yes to enforce ESLint style
- When asked to overwrite
package.json
,.eslintrc.josn
andindex.js
say No
- Select
- Now you need to customise the functions for your use. Open
functions/config/constants.js
in your preferred IDE. Inconstants.js
you will need update the values of the below properties. The other props in the file can also be updated but those are optional.- For
AUDIO_FILE_BUCKET_URL_PREFIX
andGOOGLEAPI_REDIRECT
replace[PROJECT_ID]
with your Firebase project ID - For
API_ORIGIN_WHITELIST
replace[APPSCRIPT_PROJECT_KEY]
with your AppScriptsProject key
- For
- Now open
functions/language/blurts.json
. The strings in this file are used by Cloud Text-to-Speech to create the blurts. You can modify these to match your project's needs. - Rename the folder
functions/keys-sample
tofunctions/keys
- Now open the project root in
Terminal
orCommand Line
and typefirebase deploy
- Once deployment has finished note down the
Hosting URL
(e.g.https://[PROJECT-ID].firebaseapp.com
) and the domain of theFunctions URL
(e.g.us-central1-[PROJECT-ID].cloudfunctions.net
)
- Go to Google Cloud Console, make sure to login using the same account you used to setup Firebase
- Select the project name you created in Firebase
- Go to
APIs & Services > Library
- Search for
Cloud Text-to-Speech API
- Select it and then press the Enable button.
- If you have not enabled billing you will be prompted to enable it. Follow the on-screen instructions to enable billing
- Go back to
APIs & Services > Library
and search forGoogle Calendar API
- Select it and press the Enable button
- Go to
APIs & Services > Credentials > OAuth consent screen
- Under
Support email
select an email address
- Scroll down add the
Functions URL
domain underAuthorized domains
. For example:us-central1-[PROJECT-ID].cloudfunctions.net
- Then add the
Hosting URL
toApplication Homepage link
andApplication Privacy Policy link
. . For example:https://[PROJECT-ID].firebaseapp.com
. Then press save.
- This should redirect you back to
APIs & Services > Credentials
. UnderOAuth 2.0 client IDs
click onWeb client (auto created by Google Service)
- Under
Authorized redirect URIs
addhttps://us-central1-[project-id].cloudfunctions.net/oauthcallback
replacing[project-id]
with your Firebase project ID. Then press save.
- This should redirect you back to
APIs & Services > Credentials
. Now under underOAuth 2.0 client IDs
download the JSON file forWeb client (auto created by Google Service)
- Rename the file to
calendar.json
and place into your project folder underfunctions>keys
. You may need to create thekeys
folder if you do not have it or you may need to replacecalendar.json
if one already exists. - Go back to
Google Cloud Console
and openAPIs & Services > Credentials
and selectCreate credentials > Service account key
- Create
New Service account
and name itTTS
. Make sure the key type is set toJSON
and role is set toProject > Owner
. Then pressCreate
- The JSON will autodownload. Rename it to
tts.json
and place into your project folder underfunctions > keys
. - Now open the project root in
Terminal
orCommand Line
and typeFirebase deploy
- Go to Dialogflow and login using the same account you used to access Firebase.
- If you don't have an account it's free to sign up and use.
- Create a new agent
- Give it a name e.g.
CommunityKeijiban
- Set the agent's default language and timezone
- For Google Project select the Firebase project you just created e.g.
community-keijiban
- Press "Create"
- Give it a name e.g.
- Once created select the newly created agent and go to the settings page
- Click on
Export and Import
- Click
IMPORT FROM ZIP
, select the fileassets/dialogflow.zip
from your project folder and type the word IMPORT to enable the import button.- After importing if
ja
does not display under your agent name you can add it by going toLanguages
in the Agent settings and selectingJapanese - ja
from the drop down.
- After importing if
- Now click on
Fullfilment
and enable theWebhook
option. - Then copy
https://us-central1-[PROJECT-ID].cloudfunctions.net/dialogflowWebhook
, replace[PROJECT-ID]
with your Firebase project ID, into the URL field - Under
DOMAINS
selectEnable webhook for all domains
then pressSave
. - In Dialogflow click on
Integrations
on the main menu and then click onIntegration Settings
under Google Assistant. A modal window will popup - Toggle on
Auto-preview changes
- Click on
Test
to goto the Actions on Google Console - Go to
Setup > Invocation
- Enter the name you want to use to invoke your action under
Display Name
e.g. Community Keijiban- Tip: For best results use two words for your display name.
- Go to
Advanced Options >Account Linking
- Select
Yes, allow users to sign up for new accounts via voice
and pressNext
- Select
Google Sign In
and pressNext
- Take note of the
Client ID
and then infunctions/keys
in your project folder openconstants.js
. Replace[CLIENT-ID]
with the client ID from Actions on Google console:
module.exports = {
ACTIONS_ON_GOOGLE_CLIENT_ID: '[CLIENT-ID]'
};
- Now open the project root in
Terminal
orCommand Line
and typeFirebase deploy
- Once deployed succesfully open a browser window and go to this website, replacing
[project-id]
with your Firebase project ID:https://us-central1-[project-id].cloudfunctions.net/authgoogleapi
- The Sign-in with Google page will display. Select the account that used to create your Firebase project. Click
Allow
for prompts. If succesfull you will see:App successfully configured with new Credentials. You can now close this page.
- Open
index.js
insidefunctions
folder in your project folder with your prefferred IDE - Then comment out lines 131 to 157 (this code is used for authorising the Cal. API and is only needed once).
- Now open the project root in
Terminal
orCommand Line
and typeFirebase deploy
- Open the Google Sheet you copied
- Select the
Groups
sheet - Add new group name in row 1 (header)
- Add user’s email to respective group
- Once done, go to
Sync > Update Groups
in toolbar, if this is your first time doing it follow the on screen instructions to authorize access.
- Open the Google Sheet you copied
- Select the
Events
sheet - Go to
Sync > Add Event/Announcement
in the toolbar - A form will appear on the left side
- Enter event’s details, select the
Event
type - Select one or more (hold shift + click, to select more) groups of which the event belongs to
- Check “Active” to mark the event as an active event
- Click “Submit”
- Once done, go to
Sync > Update Events
in toolbar, if this is your first time doing it follow the on screen instructions to authorize access.
- Go to the Actions on Google Console and select your project
- Click on
Test > Simulator
and try it out. You can also do this directly on your Google Assistant/Home that is logged in with you account.- Tip: If the Home says you do not have access or there is no action try sharing the Voice App with yourself from Actions on Google Console
You can find the parts we used below, or use similar parts you might already have lying around.
- LOLIN(Wemos) D1 Mini Pro ESP8266 WiFi
- Micro USB cable (data-syncing)
- Google Home, Google Mini or Phone with the Google Assistant (Android or iOS devices)
- USB Driver. The driver might be different if using a different board.
- CP2104 USB Driver (for LOLIN(Wemos) D1 Mini Pro)
- Arduino IDE
- Arduino IDE
version 1.8.9
has an issue compilingESP8266WebServer
. If1.8.9
is the latest version try downloading a previous version such as1.8.8
.
- Arduino IDE
- Open the
Arduino IDE
- Go to
Arduino > Preferences
- Copy and paste into the Additional Board Manager URLs field: http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Press OK
- Restart the Arduino IDE
- Open the
Arduino IDE
- Go to
Tools > Board > Boards Manager
- Filter by ESP8266 and click install on
esp8266 by ESP8266 Community
version 2.4.2 - Close the Boards Manager Window
- Open the Arduino IDE
- Go to
Sketch > Include Library > Manage Library
then filter for and install the following libraries:- EasyNTPClient (v1.1.0)
- ArduinoJson (v5.13.4)
- Esp8266-google-home-notifier (v1.0.6)
- Esp8266-google-tts (v1.0.7)
- Close the Library Manager window once all libraries are installed
- Go to
Tools > Board
- Select LOLIN(Wemos) D1 Mini Pro as your board or if you are holding non-pro version, choose LOLIN(Wemos) D1 R2 & Mini or any other board you are using
- Go to
Tools > Upload Speed
- Select
921600 baud
- Go to
Tools > Port
- Select the matching COM port for your USB cable. It should be something like
USB.SLABtoUART
or/dev/cu.wchusbserial14530
or/dev/cu.wchusbserial1420
(if you don't see it plug in your microcontroller and try again) - Go to
Tools > CPU Frequency
- Select
160 Mhz
- Open your Voice app on the Google Home
- In English say "Talk to Community Keijiban"
- Tip: If the Home says you do not have access or there is no action try sharing the Voice App with yourself from Actions on Google Console
- When your app runs for the first time it will ask you to sign in. You will need to do this to use the app.
- Tip: If you get stuck in a sign in loop… something like the below please check you have allowed the Assistant to use personal information.
- “Alright no problem- just so you know you will not be able to use your account with Community Keijiban. but you can come back and sign in again”
- Tip: If you get stuck in a sign in loop… something like the below please check you have allowed the Assistant to use personal information.
- Once signed in you can ask your app for your "Signal ID" by saying "What is my Signal ID" or simply "Signal ID". The signal id is used by the microcontroller to identify your account.
- Tip: It's easier to do this on the phone as it will return a written response which you can then copy for the next steps.
- Plug a USB B Mini into the microcontroller to power it and connect the other end of the cable into your computer.
- Open the Notify file you downloaded from step 1 in the Prerequisites for flashing microcontroller section. Make sure you open the INO file (Notify.ino). This should open the Arduino IDE.
- Also open
Config.h
in the Arduino IDE and replace:[PROJECT_ID]
inFIREBASE_URL
with your Firebase project Id.YOUR_WIFI_NETWORK
andYOUR_WIFI_PASSWORD
with your WiFi details.your-signal-id
with your Signal ID.YOUR_HOME_SPEAKER_NAME
with the name of the device you want to Cast to. You can get this from the Home App (see below screenshot):
- Save it.
- Click ➡️ (right arrow) icon to upload the code to your microcontroller.
- If the program fails to compile with references to
ESP8266WiFi
andWiFiClientSecure
. Try downloading and installing an older version of Arduino IDE (v1.8.8).
- If the program fails to compile with references to
- The microcontroller's LED will turn on when connected to your network and the Google Home will make a noise to confirm its connection.
Ideas on how to extend this project
- Currently the project only supports Japanese and English. This can be extended to support other languages with a few modifcations to the code.
- Close the loop by adding an attending status on the Google Sheet
- Change what the app says or add a bit of your own personality. You can do this directly in Dialogflow in the
Intents
section - Support your blurts by adding a LED or Servo to your micocontroller
- Create a case for your micocontroller out of paper, cardboard or even 3D print one
- Change the voice of your app, you can do this in Actions on Google Console
- Add recurring announcements/blurts
Made by Toaster and friends at the Google Creative Lab.
Copyright 2019 Toaster Ltd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.