diff --git a/samples/google/gmail/README.md b/samples/google/gmail/README.md index 1edfd0f3..e30fabcf 100644 --- a/samples/google/gmail/README.md +++ b/samples/google/gmail/README.md @@ -1,3 +1,4 @@ + # Gmail Sample This AutoKitteh project demonstrates 2-way integration with @@ -12,12 +13,11 @@ This AutoKitteh project demonstrates 2-way integration with 1. Install and start a [self-hosted AutoKitteh server](https://docs.autokitteh.com/get_started/quickstart), - or use AutoKitteh Cloud + or use AutoKitteh Cloud. 2. Optional for self-hosted servers (preconfigured in AutoKitteh Cloud): - [Enable Google connections to use OAuth 2.0](https://docs.autokitteh.com/integrations/google/config) - - [Enable Slack connections to use an OAuth v2 app](https://docs.autokitteh.com/integrations/slack/config) 3. Run these commands to deploy this project's manifest file: @@ -29,33 +29,24 @@ This AutoKitteh project demonstrates 2-way integration with 4. Initialize this project's connections: - Google Sheets: with user impersonation using OAuth 2.0 (based on step 2), - or a GCP service account's JSON key - - Slack: with an OAuth v2 app (based on step 2), or a Socket Mode app + or a GCP service account's JSON key. > [!TIP] > The exact CLI commands to do so (`ak connection init ...`) will appear in > the output of the `ak deploy` command from step 3 when you create the -> project on the server, i.e. when you run that command for the first time. +> project on the server, i.e., when you run that command for the first time. ## Usage Instructions -1. Run a slash command of the Slack app that you initialized in step 4 above, - with any of these commands as the slash command's text: - - - `gmail get profile` - - `gmail drafts list [optional query]` - - `gmail drafts get ` - - `gmail messages list [optional query]` - - `gmail messages get ` - - `gmail messages send ` - -2. See the Slack app's DM responses to you +1. Run these commands to interact with Gmail via HTTP trigger using query parameters: -3. Send to yourself an email, using the Slack slash command with this text: - - ``` - gmail messages send + ```shell + curl -i "http://localhost:9980/webhooks/SLUG?cmd=get_profile" + curl -i "http://localhost:9980/webhooks/SLUG?cmd=list_drafts&query=optional_query" + curl -i "http://localhost:9980/webhooks/SLUG?cmd=get_draft&draft_id=" + curl -i "http://localhost:9980/webhooks/SLUG?cmd=list_messages&query=optional_query" + curl -i "http://localhost:9980/webhooks/SLUG?cmd=get_message&message_id=" + curl -i "http://localhost:9980/webhooks/SLUG?cmd=send_message&text=" ``` -4. See the resulting message in the specified Slack channel - which is a - result of handling a mailbox change event from Gmail +2. View the responses in your terminal after making the requests. diff --git a/samples/google/gmail/program.py b/samples/google/gmail/program.py index 99e757d2..4bfa600b 100644 --- a/samples/google/gmail/program.py +++ b/samples/google/gmail/program.py @@ -34,29 +34,30 @@ def on_http_get(event): params = event.data.url.query cmd = params.get("cmd") - if cmd == "get_profile": - _get_profile() - elif cmd == "list_drafts": - _drafts_list(params.get("query", "")) - elif cmd == "get_draft": - _drafts_get(params.get("draft_id")) - elif cmd == "list_messages": - _messages_list(params.get("query", "")) - elif cmd == "get_message": - _messages_get(params.get("message_id")) - elif cmd == "send_message": - _messages_send(params.get("text")) - else: - return "Unknown command" + match cmd: + case "get_profile": + _get_profile() + case "list_drafts": + _drafts_list(params.get("query", "")) + case "get_draft": + _drafts_get(params.get("draft_id")) + case "list_messages": + _messages_list(params.get("query", "")) + case "get_message": + _messages_get(params.get("message_id")) + case "send_message": + _messages_send(params.get("text")) + case _: + return "Unknown command" def _get_profile(): """https://developers.google.com/resources/api-libraries/documentation/gmail/v1/python/latest/gmail_v1.users.html#getProfile""" resp = gmail.getProfile(userId="me").execute() print(resp["emailAddress"]) - print(f"Total no. of messages: {resp['messagesTotal']}") - print(f"Total no. of threads: {resp['threadsTotal']}") - print(f"Current History record ID: {resp['historyId']}") + print("Total no. of messages:", resp["messagesTotal"]) + print("Total no. of threads:", resp["threadsTotal"]) + print("Current History record ID:", resp["historyId"]) def _drafts_get(id):