All Projects → IBM-Cloud → openwhisk-slackapp

IBM-Cloud / openwhisk-slackapp

Licence: other
A serverless Slack app built with Slack Events API and IBM Cloud Functions

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to openwhisk-slackapp

github-traffic-stats
Manage and automatically collect Github traffic statistics for repositories
Stars: ✭ 30 (+25%)
Mutual labels:  ibm-cloud, ibm-cloud-solutions
jpetstore-kubernetes
Modernize and Extend: JPetStore on IBM Cloud Kubernetes Service
Stars: ✭ 21 (-12.5%)
Mutual labels:  ibm-cloud, ibm-cloud-solutions
awesome-ibmcloud
A curated list of awesome IBM Cloud SDKs, open source repositories, tools, blogs and other resources.
Stars: ✭ 77 (+220.83%)
Mutual labels:  ibm-bluemix, ibm-cloud
vpc-tutorials
Companion scripts to VPC tutorials
Stars: ✭ 14 (-41.67%)
Mutual labels:  ibm-cloud, ibm-cloud-solutions
slack-chatbot-database-watson
Code for the solution tutorial "Build a database-driven Slackbot" (chatbot) with a custom extension in IBM Watson Assistant
Stars: ✭ 23 (-4.17%)
Mutual labels:  ibm-cloud, ibm-cloud-solutions
cloudco-insurance
A modern insurance company. The application showcases cognitive and cloud computing ideas in the context of insurance.
Stars: ✭ 43 (+79.17%)
Mutual labels:  ibm-cloud, ibm-cloud-solutions
speech-to-text-code-pattern
React app using the Watson Speech to Text service to transform voice audio into written text.
Stars: ✭ 37 (+54.17%)
Mutual labels:  ibm-cloud
slack-term
Slack client for your terminal
Stars: ✭ 6,074 (+25208.33%)
Mutual labels:  slack
vscode-chat
Chat with your team while you collaborate over code using VS Live Share
Stars: ✭ 496 (+1966.67%)
Mutual labels:  slack
slack-ascii
ASCII Emoticons for Slack!
Stars: ✭ 15 (-37.5%)
Mutual labels:  slack
kwatchman
Watch for k8s resources changes and trigger chains of handlers
Stars: ✭ 24 (+0%)
Mutual labels:  slack
humhub-oauth
Social OAuths built for the Social Platform HumHub
Stars: ✭ 16 (-33.33%)
Mutual labels:  slack
gmg
Green Mountain Grills web app.
Stars: ✭ 54 (+125%)
Mutual labels:  slack
SlackMC
Link Slack to Minecraft!
Stars: ✭ 61 (+154.17%)
Mutual labels:  slack
enhanced-slack
🌴 PoC Slack enhancer/injector
Stars: ✭ 48 (+100%)
Mutual labels:  slack
openwhisk-workshops
IBM Cloud Functions (Apache OpenWhisk) workshops
Stars: ✭ 16 (-33.33%)
Mutual labels:  ibm-cloud
emojibot
Emojibot is a Slack bot that announces new custom emoji to a specific channel.
Stars: ✭ 17 (-29.17%)
Mutual labels:  slack
djangobot
Bridge between Slack and Django, via Channels
Stars: ✭ 66 (+175%)
Mutual labels:  slack
react-slack-rtm
Demo Slack RTM chat built with ReactJS and Django
Stars: ✭ 17 (-29.17%)
Mutual labels:  slack
notify
推送通知 sdk(Bark、Chanify、钉钉群机器人、Discord、邮件、飞书群机器人、Gitter、Google Chat、iGot、Logger、Mattermost、Now Push、PushBack、Push、PushDeer、PushPlus、QQ 频道机器人、Rocket Chat、Server 酱、Showdoc Push、Slack、Telegram、Webhook、企业微信群机器人、息知、Zulip)。
Stars: ✭ 335 (+1295.83%)
Mutual labels:  slack

A serverless Slack app built with IBM Cloud Functions and Slack Events API

This sample shows how to build a serverless Slack app using Slack Events API to receive events, with IBM Cloud Functions to process these events.

A previous version of this sample was using API Connect to expose the actions as HTTP endpoints. With the introduction of web actions in Cloud Functions this was no longer needed. You can browse this tag to view the code using API Connect.

Overview

Built using IBM Cloud, the app uses:

  • Cloud Functions - to implement the app bot and commands
  • Cloudant - to keep track of app installations
  • and Slack Events API.

When a user installs the app in a Slack team, or interacts with a bot user, or uses a custom command, Slack calls the app implementation. Slack will talk directly with IBM Cloud Functions.

From the perspective of the developer of the Slack app, there is no server involved, only actions in a serverless environment. Furthermore the code is not running if no user interacts with the app and if the app gets popular, it will benefit from IBM Cloud Functions scalability.

Architecture

architecture_diagram digraph G { node [fontname = "helvetica"] rankdir=LR user -> slack slack -> openwhisk openwhisk -> cloudant slack [shape=square style=filled color="%23e9a820" fontcolor=white label="%23 Slack"] openwhisk [shape=circle style=filled color="%23325c80" fontcolor=white label="Cloud Functions"] cloudant [shape=circle style=filled color="%2372c7e7" fontcolor=white label="Cloudant"] } architecture_diagram )

In this sample, we will:

  • create the Slack app in Slack,
  • prepare the Cloud Functions environment, creating the actions implementing our Slack app,
  • complete the integration by updating the endpoints in the Slack app,
  • add our Slack app to a Slack team,
  • test our Slack app.

Requirements

To deploy this app, you need:

Your own Slack team is recommended if you want to play with the integration without impacting others.

Create the Slack app

  1. Proceed to the new app creation in Slack

  2. Type a name for your app, select your Slack team.

  3. Click Create

  4. View the App Credentials

We will need the Client ID, Client Secret and Verification Token in the next steps.

At this stage, we will put the configuration of the Slack app on hold. For the next app configuration steps to work we need to have our actions up and running.

Deploy the IBM Cloud Functions

Get the code

  • Clone the app to your local environment from your terminal using the following command:

    git clone https://github.com/IBM-Cloud/openwhisk-slackapp.git
    
  • or Download and extract the source code from this archive

Create the IBM Cloud Cloudant service

  1. Open the IBM Cloud console

  2. Create a Cloudant instance named cloudant-for-slackapp.

  3. Open the Cloudant service dashboard and create a new database named registrations

  4. Select the database

  5. Create a new document.

  6. Replace the default JSON with the content of the file cloudant-designs.json

Deploy from Linux or macOS

  1. Copy the file named template.local.env into local.env

    cp template.local.env local.env
    
  2. Get the service credentials for the Cloudant service created above and set CLOUDANT_url, CLOUDANT_apikey in local.env to the corresponding value (url and apikey).

  3. Set the values for SLACK_CLIENT_ID, SLACK_CLIENT_SECRET, SLACK_VERIFICATION_TOKEN - these are the App Credentials we've seen in the previous steps.

  4. Ensure your ibmcloud fn command line interface is property configured with:

    ibmcloud fn list
    

    This shows the packages, actions, triggers and rules currently deployed in your namespace.

  5. Create the actions:

    ./deploy.sh --install
    

    If all goes well it outputs:

    Creating slackapp package
    ok: created package slackapp
    Adding app registration command
    ok: created action slackapp/slackapp-register
    Adding app event processing
    ok: created action slackapp/slackapp-event
    Adding app command processing
    ok: created action slackapp/slackapp-command
    OAuth URL:
    https://us-south.functions.cloud.ibm.com/api/v1/web/<your-namespace-id>/slackapp/slackapp-register
    Command URL:
    https://us-south.functions.cloud.ibm.com/api/v1/web/<your-namespace-id>/slackapp/slackapp-command
    Event Subscription Request URL:
    https://us-south.functions.cloud.ibm.com/api/v1/web/<your-namespace-id>/slackapp/slackapp-event
    

    Note: the script can also be used to --uninstall the Cloud Functions artifacts to --update the artifacts if you change the action code, or simply with --env to show the environment variables set in local.env.

Deploy from Windows

  1. Copy the file named template.local.cmd into local.cmd

    copy template.local.cmd local.cmd
    
  2. Get the service credentials for the Cloudant service created above and set CLOUDANT_url in local.cmd to the corresponding value (url). Make sure you take the full url including the username and password https://username:[email protected].

  3. Set the values for SLACK_CLIENT_ID, SLACK_CLIENT_SECRET, SLACK_VERIFICATION_TOKEN - these are the App Credentials we've seen in the previous steps.

  4. Ensure your ibmcloud fn command line interface is property configured with:

    ibmcloud fn list
    

    This shows the packages, actions, triggers and rules currently deployed in your namespace.

  5. Create the actions:

    deploy.cmd --install
    

    If all goes well it outputs:

    Creating slackapp package
    ok: created package slackapp
    Adding app registration command
    ok: created action slackapp/slackapp-register
    Adding app event processing
    ok: created action slackapp/slackapp-event
    Adding app command processing
    ok: created action slackapp/slackapp-command
    

    Note: the script can also be used to --uninstall the Cloud Functions artifacts to --update the artifacts if you change the action code, or simply with --env to show the environment variables set in local.cmd.

Our actions are ready. Back to the Slack app configuration.

Complete the Slack app configuration

Add an Event Subscription

  1. Go to the Event Subscriptions section of your app

  2. Enable Events

  3. Set the Request URL to the URL of the slack-event web action. The URL should look like https://us-south.functions.cloud.ibm.com/api/v1/web/your-namespace-id/slackapp/slackapp-event

    Slack will contact this URL immediately. It should turn to Verified if the Cloud Functions configuration steps worked.

Listen to Bot messages

  1. Add a new Bot User Event for message.im

    This allows us to react to direct messages sent to a bot. We could select more event type but for our simple app will only deal with this one today.

  2. Save the changes

Set the callback URL for authentication

  1. Under OAuth and Permissions, add a new Redirect URL. This URL will be called when a user installs your application in a team. It should point to the slackapp-register web action. The URL should look like https://us-south.functions.cloud.ibm.com/api/v1/web/your-namespace-id/slackapp/slackapp-register

  2. Click Save URLs

Create a new command

  1. Under Slash Commands, Create New Command

  2. Set the values

    1. Command: /myserverlessapp

    2. Request URL: URL of the slackapp-command web action. The URL should look like https://us-south.functions.cloud.ibm.com/api/v1/web/your-namespace-id/slackapp/slackapp-command

    3. Short Description: A test command

    4. Usage Hint: [param1] [param2]

  3. Save. This automatically creates a bot for the app.

Give the bot the permission to talk

  1. Go to OAuth & Permissions.
  2. Under Scopes / Bot Token Scopes, add the two OAuth Scopes: chat:write and users:read

Our app is finally ready to be installed!

Add the app to your team

  1. To see what's happening behind the scene as Slack calls our actions, open a new command prompt and run

    ibmcloud fn activation poll
    

    Leave it running. Actions triggered by Slack will show up there

  2. Go to Manage Distribution

  3. Click the Add the Slack button

  4. Authorize the app

    After a few seconds, the app is installed. You should see logs appearing in the activation polling as Slack will be sending the registration info we will use later to interact with Slack channels and users.

    In your web browser, you should see Registration was successful. You can try the command in Slack or send a direct message to the bot.

    Ideally you would redirect to another page once the registration is completed.

Test the integration

  1. Go into your team in Slack

  2. Send a direct message to our new bot friend

  3. The bot replies

  4. Go to the #general channel (although this could work from any place in Slack) and type /my you should see the custom command

  5. Try the command /myserverless two params as example

Code Structure

Cloud Functions - Deployment Script

File Description
deploy.cmd
deploy.sh
Helper script to install, uninstall, update the actions.

Cloud Functions - Actions

File Description
slackapp-register.js Handles the installation of the app in a team. It stores the authorization token in Cloudant for future use by the bot and commands.
slackapp-event.js Handles events triggered by the Events API. In this sample, it handles messages sent to the bot user and simply echoes the message sent by the user.
slackapp-command.js Handles custom commands. In this sample, it echoes the command parameters.

Contribute

Please create a pull request with your desired changes.

Troubleshooting

Cloud Functions

Polling activations is good start to debug the action execution. Run

ibmcloud fn activation poll

and send a message to the bot or use a custom command.

License

See License.txt for license information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].