https://github.com/lucasroesler/openfaas-slack-bot
Creating OpenFaaS Slack bot templates
https://github.com/lucasroesler/openfaas-slack-bot
openfaas openfaas-template slack slack-commands
Last synced: 2 months ago
JSON representation
Creating OpenFaaS Slack bot templates
- Host: GitHub
- URL: https://github.com/lucasroesler/openfaas-slack-bot
- Owner: LucasRoesler
- Created: 2020-02-02T20:25:36.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-06-14T07:48:36.000Z (over 5 years ago)
- Last Synced: 2025-08-02T22:52:58.771Z (3 months ago)
- Topics: openfaas, openfaas-template, slack, slack-commands
- Language: Python
- Size: 13.7 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pyslash OpenFaaS Slack Slash Command Template
## Usage
1. `faas-cli template pull faas-cli template pull https://github.com/LucasRoesler/openfaas-slack-bot`
2. `faas-cli new bot --lang=pyslash`
3. Update the stack file to include the template configuration
```yaml
configuration:
templates:
- name: pyslash
source: https://github.com/LucasRoesler/openfaas-slack-bot
```
3. Wite your command logic in `./bot/handler.py`
## Writing slash commands
The abosolute smallest example slash command looks like this
```py
import sanic
from sanic.response import json
from . import secrets
from .slacker import Slacker
# To create a new app go to https://api.slack.com/apps?new_app=1
# Manager your apps:
# https://api.slack.com/apps
# Manage slash commands in an app:
# https://api.slack.com/apps/:id/slash-commands
bot = Slacker(
token=secrets.slack_api_token,
signing_secret=secrets.slack_signing_secret,
)
# this would be called by the `/hello` slash command.
#
# the url will be /function//hello
@bot.slash_cmd("hello")
async def hello(request: sanic.request.Request):
return json({
"response_type": "in_channel",
"text": "*hi there*",
})
```
You must also set the secrets for your Slack API token an dsigning secret in your stack file:
```yaml
functions:
bot:
lang: pyslash
handler: ./bot
image: theaxer/test-bot:latest
secrets:
- slack-api-token
- slack-signing-secret
```
## Deployment
Configure your Slack bot. Create or manage your app at https://api.slack.com/apps
Get your bot's API token from the`https://api.slack.com/apps//install-on-team` and your
signing key from `https://api.slack.com/apps//general`
```sh
faas-cli secret create slack-api-token --from-literal=xoxb-921547957923-933041549141-J0i1Nt9ZLBoL6BCEpXoGEQrK
faas-cli secret create slack-signing-secret --from-literal=7bd05b1bca10d191f69de20866c4c890
faas-cli up
```
Each Slash command that you register in your handler must also be registered in the Slack UI,
`https://api.slack.com/apps//slash-commands`
The URL for each slash command will be `http:///function//`