Skip to content

Instantly share code, notes, and snippets.

@MTRNord
Last active February 26, 2017 18:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MTRNord/4ff0b22a779fbfeb0f57a72ca6acc5f7 to your computer and use it in GitHub Desktop.
Save MTRNord/4ff0b22a779fbfeb0f57a72ca6acc5f7 to your computer and use it in GitHub Desktop.

Requires plugin: lookup.sheetapi

NOTE: You need a Serviceaccount (explained below) and you need to share the sheet with it.

/bot lookup [<MAX] <keyword>

  • Need to enable in config: spreadsheet_enabled, spreadsheet_url and spreadsheet_credentials_file
  • spreadsheet_worksheet allows you to optionaly define the worksheet to use by name.
  • Will look up each row of a spreadsheet and if the keyword is found will return the whole row
  • if <MAX is specified, the lookup will return rows up to the MAX integer specified. (Default = 5)
  • As of 2.6, spreadsheet_enabled and spreadsheet_url can be defined on a conversation-level config

How to get a GoogleServiceaccount

  1. Browse to the Gogle Developers Console and login via any Google Account (I recommend using your bot account)
  2. Add a new Project with a name you want if you have not already created one.
  3. Go to "API&auth" and activate the Drive API
  4. Go to Credentials and Choose under "New Credentials" the Option "Service Account Key"
  5. Upload the automaticly downloaded json file in "~/.local/share/hangoutsbot/creds.json" (or any directory that the bot is able to access)
  6. Add "spreadsheet_credentials_file": "~/.local/share/hangoutsbot/creds.json" to the config file. Remember to change the filename in this path to the filename of your json file.

Example

Note: Due to a missing feature in the here used lib it isn't currently possible to use a public sheet with the bot. This PR can be found here. To use the example you need to manually share the sheet with the bot

Using this test spreadsheet

config.json fragment:

...,
"spreadsheet_enabled": true,
"spreadsheet_url": "https://docs.google.com/spreadsheets/d/1jMEtvYhTyuso-ZV0tCgOw4oZ9xDwUgWPiymnEmBw02s",
"spreadsheet_credentials_file": "~/.local/share/hangoutsbot/creds.json",
...

Bot output:

User: /bot lookup dc
Bot:  Results for keyword "dc":
2 rows found. Only returning first 5.
Row 1: | bdc | I | J | K | L | 
Row 2: | dca | M | N | O | P | 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment