Giter Club home page Giter Club logo

slack-app-cloud-functions's Introduction

Google Cloud Functions for Slack apps

Cloud Functions for

Google has a guide to Slack apps, but it is outdated and using Legacy tokens from Slack.
These Cloud Functions implement the newer and safer way for Slack apps to verify that the request comes from Slack: https://api.slack.com/docs/verifying-requests-from-slack

Flow

The Slack app should be configured to send a Slash command to the Google Cloud function under directory slash_command:
Slash Command

The Google Cloud function slash_command sends a short message to the user, and triggers a Slack dialog window:
Dialog

Once the user responds to the dialog, Slack sends a request to the Cloud function under directory dialog_submission, which pushes the message containing the submission data and other data sent by Slack to into a topic on Google Cloud Pub/Sub.

Setup

Prequisite:

  • You must have a Cloud Pub/Sub topic.
  • You will also need to give the user running the Dialog Cloud Function write access to that topic.
  • An app registered in Slack. This is required to get the signing secret and oauth token for deployment below.

Deploy the Cloud Functions:

Configure environment variables for the configurable options.

export slash_command=</YOUR-SLASH-COMMAND>
export pubsub_topic=projects/<YOUR-PROJECT>/topics/<YOUR-TOPIC>
export signing_secret=<YOUR_SIGNING_SECRET_FROM_SLACK>
export oauth_token=<YOUR_APPS_SLACK_OAUTH_ACCESS_TOKEN>

Slash command function:

cd src/slash_command
gcloud functions deploy slash_command --runtime python37 --trigger-http --memory=128MB --set-env-vars SLACK_SIGNING_SECRET=$signing_secret,SLACK_OAUTH_TOKEN=$oauth_token,SLACK_SLASH_COMMAND=$slash_command

Dialog handling function:

cd src/dialog_submission
gcloud functions deploy dialog_submission --runtime python37 --trigger-http --memory=128MB --set-env-vars PUBSUB_TOPIC_NAME=$pubsub_topic,SLACK_SIGNING_SECRET=$signing_secret

slack-app-cloud-functions's People

Contributors

tkamppi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.