Slack server mock is intended to be used for sub-system testing of Slack applications.
Create a settings.yaml file based on the sample file.
If you wish to return a list of channels, create a JSON file with an array of channel objects. At minimum, each entry must have a name and an ID.
In the settings.yaml
file, set slack_server.channels_path
to the location of the file.
Install poetry
- Download the code and change to the downloaded directory:
git clone https://github.com/ygalblum/slack-server-mock.git cd slack-server-mock
- Install all the requirements using poetry:
poetry install --no-root
- Run the application:
poetry run python -m slack_server_mock
The server is published in a container image on quay.
podman run --rm -it -d --name slack_server_mock --publish 3001:3001 --publish 8080:8080 --publish 8888:8888 --volume ${PWD}/settings.yaml:/app/settings.yaml:z quay.io/yblum/slack_server_mock:latest
If you are using a channels file, make sure to mount it into the container as well.
In order to make your Slack application connect with the mock server you need to override its base_url
.
Instead of:
handler = SocketModeHandler(
App(token=BOT_TOKEN),
APP_TOKEN
)
Use:
handler = SocketModeHandler(
app=App(
client=WebClient(
token=BOT_TOKEN,
base_url="http://localhost:8888"
)
),
app_token=settings.slackbot.app_token
)
The mock server provides an endpoint to send a message to the application, wait for the application response and return the accumulated ephemeral messages (if sent) and the response.
The request payload is a JSON with the key message
whose value is a string
The response payload is a JSON with two keys:
ephemeral
: List of strings. All accumulated ephemeral messageresponse
: string. The application's response
Send a message using curl
and see the response:
$ curl http://localhost:8080/message -d'{"message": "hello"}'
{"answer": "Hello to you too", "ephemeral": ["I'll be right with you"]}