Direct Messaging with Dify Bot in Slack: How to Enable Private AI Interactions

Table of Contents

Background #

In our previous article How to Create a Dify Slack Bot, we discussed how to build an intelligent knowledge assistant in Slack using Dify. However, one question caught many users’ attention: why can we only interact with the bot by @mentioning it in public channels, rather than sending direct messages?

While some social butterflies might be comfortable asking questions in public channels, many users prefer to communicate with AI assistants privately, avoiding exposing their queries or concerns to the entire team. Today, we’ll explore how to implement direct messaging functionality with the Dify Slack Bot, making your AI interactions more private and personalized.

Feature Demo #

Here’s a brief video demonstration showing how to direct message the Dify Bot:

Implementation Steps #

1. Deploy Dify Bot #

First, we need to deploy the Dify Bot service. We’ll use Docker to simplify the deployment process:

  1. Create a project directory and download the configuration file:
mkdir dify-bot-9db
curl https://raw.githubusercontent.com/graysonchen/dify-bot/refs/heads/stable/.env.example > .env
  1. Configure environment variables by editing the .env file:
# Dify Configuration
DIFY_API_BASE_URL=https://api.dify.ai/v1
DIFY_API_KEY=app-OxxxxxxxxxxxxxTxxxxxxx

# Slack Configuration
SLACK_BOT_TOKEN=xoxb-xxxxxxxxxxxxx-xxxxxxxxxxxxx-V25CBgH7347xxxxxxxxxxxxx
SLACK_APP_TOKEN=xapp-1-A05KP4WSVS4-xxxxxxxxxxxxx-4208xxxxxxxxxxxxxca9dxxxxxxxxxxxxxc33a0d8bb311d40axxxxxxxxxxxxx
  1. Run the service using Docker:
# Pull the latest image
docker pull graysonchen/dify-bot:latest

# Run the container
docker run -itd --env-file .env --name=dify-slack-9db graysonchen/dify-bot:latest

# Set container to auto-restart
docker update --restart=always dify-slack-9db

# Stop/Start production container
docker stop dify-slack-9db
docker start dify-slack-9db

2. Configure Slack App Permissions #

Yes, here’s how to enable the message input box for sending messages: image

To enable direct messaging with the bot, you need to properly configure your Slack App permissions:

  1. Visit the Slack Apps management page and select or create your Slack App.

image

  1. Find App Manifest in the left menu - this is the core configuration section for your App’s functionality.

image

  1. Add or modify the following configuration in the App Manifest:
features:
  app_home:
    home_tab_enabled: false
    messages_tab_enabled: true
    messages_tab_read_only_enabled: false

These configurations mean:

  • home_tab_enabled: false - Disable the Home tab
  • messages_tab_enabled: true - Enable the Messages tab
  • messages_tab_read_only_enabled: false - Allow users to send messages in DMs

3. Verify Configuration #

After completing the configuration:

  1. Search for your bot username directly in Slack
  2. Open the direct message window with the bot
  3. Type your message in the input box and send
  4. The bot will automatically respond to your questions

image

Security Considerations #

When implementing direct messaging functionality, keep these security points in mind:

  1. Safeguard API keys to prevent exposure
  2. Regularly update Docker images for security patches
  3. Monitor bot usage to prevent abuse

References #