]> git.cworth.org Git - turbot/log
turbot
3 years agoShare the rot() implementation between both Lambda and Flask implementations
Carl Worth [Sun, 11 Oct 2020 21:12:42 +0000 (14:12 -0700)]
Share the rot() implementation between both Lambda and Flask implementations

This provides a model of how to do code sharing between the two
implementations we have, (with the expectation that the code in the
"turbot" package will be generic and that code in turbot_slack and
turbot_lambda will use that common code while doing whatever
additional marshalling is necessary for their particular application
environments).

3 years agoMove top-level flask app from turbot/turbot.py to turbot_flask/turbot.py
Carl Worth [Sun, 11 Oct 2020 20:59:19 +0000 (13:59 -0700)]
Move top-level flask app from turbot/turbot.py to turbot_flask/turbot.py

This is a first baby step toward teasing apart true "library" code in
turbot, (which can be shared by both the Lambda and Flask
implementations), from code that is Flask-specific.

(For symmetry, the lambda directory is renamed turbot_lambda here as well.)

3 years agoAdd target to deploy our lambda code to AWS
Carl Worth [Sun, 11 Oct 2020 20:55:15 +0000 (13:55 -0700)]
Add target to deploy our lambda code to AWS

The existing "make deploy" target now calls out to two targets:

make flask: Deploys code to Flask app at halibut.cworth.org

make lambda: Deploys code to AWS lambda function

3 years agoStart implementing code intended to be deployed to AWS Lambda
Carl Worth [Sun, 11 Oct 2020 17:35:45 +0000 (10:35 -0700)]
Start implementing code intended to be deployed to AWS Lambda

Here, lambda/rot.py is a copy of the turbot/rot.py code, but massaged
into the calling conventions of AWS Lambda (and without yet any actual
code to integrate with Slack in either direction).

3 years agoUse a thread for creating the Google Sheet when a new channel is created
Carl Worth [Fri, 9 Oct 2020 22:41:11 +0000 (15:41 -0700)]
Use a thread for creating the Google Sheet when a new channel is created

This allows us to return quickly so that Slack doesn't retry sending the event.

As implemented in this commit, this code is a bit cheesy in that it
disables the debug mode and error handling in slack_send_message,
(since the prior implementation of that depended on having a current
Flask app, but now that we are calling this function from a thread we
don't have a current app context).

3 years agoAdd automatic refreshing of the Google Sheets token
Carl Worth [Fri, 9 Oct 2020 21:09:23 +0000 (14:09 -0700)]
Add automatic refreshing of the Google Sheets token

Otherwise, the original token expires and becomes useless after 60
minutes.

3 years agoRemove another stale file name from a comment
Carl Worth [Wed, 30 Sep 2020 14:04:56 +0000 (07:04 -0700)]
Remove another stale file name from a comment

The documentation example used "token.pickle" but we are now using
".gsheets-token.pickle". Here we switch to just "token file" in the
code comment so the comment is immune to any renaming.

3 years agoCopy template sheets to newly-created spreadsheets
Carl Worth [Tue, 29 Sep 2020 22:59:39 +0000 (15:59 -0700)]
Copy template sheets to newly-created spreadsheets

The TEMPLATE_SHEET_ID here is that of a spreadsheet in Trubot's
account that is named "Template".

3 years agoFix a stale file name embedded in a comment
Carl Worth [Tue, 29 Sep 2020 22:58:37 +0000 (15:58 -0700)]
Fix a stale file name embedded in a comment

We renamed this file recently so the comment was wrong. Re-word
the comment here so that we don't need to keep tracking the latest
name of this file.

3 years agoSet the name of newly-created sheets to match the channel name
Carl Worth [Tue, 29 Sep 2020 22:12:24 +0000 (15:12 -0700)]
Set the name of newly-created sheets to match the channel name

Much better than having dozens of sheets all named "untitled".

3 years agoInitial implement of auto-creation of Google sheets
Carl Worth [Tue, 29 Sep 2020 22:08:44 +0000 (15:08 -0700)]
Initial implement of auto-creation of Google sheets

This is implemented via a Slack event listener that's listening for
the "channel_created" event. So, whenever a new channel is created,
this code will create a new Google sheet and inject a message into
the new channel with the URL of the sheet.

3 years agoRename .turbot.env to .slack-creds.env
Carl Worth [Tue, 29 Sep 2020 22:05:21 +0000 (15:05 -0700)]
Rename .turbot.env to .slack-creds.env

I had originally chosen a generic name hoping that I could cram all
of our various credentials into this one file. But, alas, the Google
docs. credentials really want to be in a JSON file so they will be
separate.

Given that, I'll give each file a specific name, starting with this
Slack-specific file.

3 years agoMakefile: Fix DO_NOT_DEPLOY implementation to work with multiple files
Carl Worth [Tue, 29 Sep 2020 22:02:57 +0000 (15:02 -0700)]
Makefile: Fix DO_NOT_DEPLOY implementation to work with multiple files

The --exclude option to rsync expects a single file, so we need to
arrange to pass it multiple times if we have multiple files in the
value of the DO_NOT_DEPLOY variable. Fortunately, this is a perfect
job for patsubst.

3 years agoAdd a listener for the Slack "channel_created" event
Carl Worth [Tue, 29 Sep 2020 18:15:54 +0000 (11:15 -0700)]
Add a listener for the Slack "channel_created" event

Currently this just posts a simple message when a channel is
created. Eventually, we'll want to do something different such as
creating a puzzle sheet and linking/pinning it to the channel.

3 years agoBreak out rot.py and slack.py from turbot.py
Carl Worth [Tue, 29 Sep 2020 19:44:58 +0000 (12:44 -0700)]
Break out rot.py and slack.py from turbot.py

Using separate modules to make the code more maintainable.

3 years agoMake a top-level turbot package
Carl Worth [Tue, 29 Sep 2020 17:07:15 +0000 (10:07 -0700)]
Make a top-level turbot package

This will be useful as we soon start splitting up the single turbot.py
file into multiple modules that want to include things from each
other.

3 years agoIgnore the __pycache__ directory
Carl Worth [Tue, 29 Sep 2020 17:06:04 +0000 (10:06 -0700)]
Ignore the __pycache__ directory

Something keeps auto-creating this, so I know it's not source we would
ever want to commit to git.

3 years agoAbstract out two slack-related functions
Carl Worth [Tue, 29 Sep 2020 16:59:42 +0000 (09:59 -0700)]
Abstract out two slack-related functions

The two new functions are slack_is_valid_request and slack_send_reply.
These functions provide some shared code for dealing with slack to
avoid code duplication.

These functions also provide a debug mode (that doesn't use slack at
all). This is a convenience for testing the implementation of slash
commands in a local "make run" session without needing to touch Slack
endpoints at all. (Instead, all requests are considered valid and
slack replies are simply printed to stdout.)

3 years agoConvert "make run" to use "flask run" instead of direct python script execution
Carl Worth [Tue, 29 Sep 2020 15:35:46 +0000 (08:35 -0700)]
Convert "make run" to use "flask run" instead of direct python script execution

This will simplify some future work (regarding reorganizing the code into
a package, etc.) so that we don't have to try to simultaneously support
running as both a script and as a module.

3 years agoUse a raw string for a regular expression
Carl Worth [Tue, 29 Sep 2020 13:20:59 +0000 (06:20 -0700)]
Use a raw string for a regular expression

Previously, the string had an unrecognized escape sequence ('\*').
With a non-raw string we could have doubled the backslash, but it's
much cleaner to just use a raw string instead, (so that backslashes
are used for regular-expression escaping, and not also for string
escaping).

3 years agoAdd missing include of flask.make_response
Carl Worth [Tue, 29 Sep 2020 13:15:32 +0000 (06:15 -0700)]
Add missing include of flask.make_response

Revealing that I hadn't actually tested this error case (*blush*).

3 years agoFix some code style issues identified by flake8
Carl Worth [Tue, 29 Sep 2020 13:12:55 +0000 (06:12 -0700)]
Fix some code style issues identified by flake8

Some of the things fixed include TAB based indentation of a
documentation string, some unneeded semicolons, a missing exception
name, and an excessively long line.

3 years agoAdd signature verification fo the /rot slash command
Carl Worth [Sun, 27 Sep 2020 21:45:34 +0000 (14:45 -0700)]
Add signature verification fo the /rot slash command

This prevents someone abusing our bot by spoofing messages appearing
to have come from Slack. This way we won't reply to any command
request unless it actually comes from Slack.

3 years agoAdd some documentation for the functions we have defined here
Carl Worth [Sun, 27 Sep 2020 21:26:47 +0000 (14:26 -0700)]
Add some documentation for the functions we have defined here

Since we want to have maintainable code.

3 years agoAdd requirements for using Google Sheets API
Carl Worth [Sat, 26 Sep 2020 17:57:15 +0000 (10:57 -0700)]
Add requirements for using Google Sheets API

And update all other requirements while we're at it.

3 years agoAdd a route to implement a /rot slash command
Carl Worth [Sat, 26 Sep 2020 05:22:32 +0000 (22:22 -0700)]
Add a route to implement a /rot slash command

This is to be used as follows:

/rot [count] String to rotate

The optional count indicates a number of positions to rotate every
letter in the string. If it is not provided, all rotations will be
printed.

Note: The count can also be provided as an '*' character to explicitly
request all possible rotations.

3 years agoRestore handling of error events from Slack
Carl Worth [Sat, 26 Sep 2020 05:02:45 +0000 (22:02 -0700)]
Restore handling of error events from Slack

This is better than what I had copied from the example a few commits
ago because this properly logs through the python logging system, (so
the error message will appear in the Apache log file).

3 years agoFix turbot.wsgi to be able to find its environment variables
Carl Worth [Sat, 26 Sep 2020 04:47:32 +0000 (21:47 -0700)]
Fix turbot.wsgi to be able to find its environment variables

We can't rely on the current working directory of the Apache process,
so we need to use an explicit path here in order to find our file
with environment variables in it.

3 years agoPut my own creation of the Flask app back
Carl Worth [Sat, 26 Sep 2020 04:41:27 +0000 (21:41 -0700)]
Put my own creation of the Flask app back

Rather than relying on the one in the Slack events API.

This means the WSGI configuration should work once again.

3 years agoTrim down the program to not have any custom routes
Carl Worth [Sat, 26 Sep 2020 04:37:59 +0000 (21:37 -0700)]
Trim down the program to not have any custom routes

I'm just verifying here that I don't need to have these in order to
get the Slack challenge verification to work.

3 years agoAdd Slack dependencies and minimum boilerplate to our flask app
Carl Worth [Sat, 26 Sep 2020 02:57:59 +0000 (19:57 -0700)]
Add Slack dependencies and minimum boilerplate to our flask app

This entirely replaces our flask setup, (which also breaks our current
WSGI setup too) but is based on the exact demo code from:

https://github.com/slackapi/python-slack-events-api/blob/main/example/example.py

I want to start with this to ensure I can at least get a correct
challenge working. After I get this working this way, I'll plan to put
direct flask code back in place and integrated with the web server via
WSGI.

3 years agoInitial commit of turbot
Carl Worth [Sat, 26 Sep 2020 02:01:48 +0000 (19:01 -0700)]
Initial commit of turbot

Turbot will eventually be a Slack bot for the Halibut That Bass team.

As of this commit, turbot.py is just a simple flask app implementing a
REST API (to query, add, delete TODO items). Additionally, this commit
includes the Makefile pieces to manage python dependencies and to
deploy the program to our server.

There's not yet any actual Slack-application code here yet.