Building an Automated APK QR Code Generator Bot with Jenkins CI/CD and Slack Integration

Streamlining mobile app distribution by automatically generating and sharing QR codes through Slack

Building an Automated APK QR Code Generator Bot with Jenkins CI/CD and Slack Integration



Overview

In mobile app development environments, distributing APK builds to testers can be surprisingly cumbersome. You copy download links and paste them into Slack, then testers must manually enter or copy these links on their mobile devices. Long URLs are particularly prone to input errors.

To solve this inconvenience, I developed a bot that automatically converts APK download links into QR codes and sends them to Slack channels. When Jenkins builds complete, QR codes are automatically generated and sent to Slack, allowing testers to simply scan the QR code with their mobile devices to download the APK instantly.

This article shares the complete process of building a Python Flask-based Slack Bot and deploying it on Kubernetes.



Key Features

This bot goes beyond simple QR code generation to include several features needed in production environments.

Core Functionality


Security and Stability


Developer Friendly



System Architecture

Jenkins/GitLab CI/GitHub Actions
    ↓ (HTTP POST with X-API-Key)
Ingress (slack-qr-bot.concrit.us)
    ↓
Kubernetes Service
    ↓
Flask Application Pod
    ├─ API Key Authentication
    ├─ Rate Limiter
    ├─ JSON Logger
    └─ Retry Logic (Tenacity)
        ↓
Slack API (files.upload_v2)



Technology Stack



Implementation Process

1. Slack App Configuration

First, create a new app in the Slack API and configure necessary permissions.

Required Bot Token Scopes:

After installing the app in your workspace, copy the Bot User OAuth Token. The format starts with xoxb-.


If you encounter app addition errors, execute the following command in the channel:

/invite @your-bot-name

Note: When modifying Scopes, you must Reinstall the App.


2. Project Structure

slack-qr-bot
├── Dockerfile
├── README.md
├── backup
│   └── app.py.bak
├── img
│   └── slack-qr-bot-example.png
├── k8s
│   ├── api-key-secret.yaml
│   ├── deployment.yaml
│   ├── harbor-robot-secret.yaml
│   └── slack-token-secret.yaml
├── requirements.txt
└── src
    ├── __init__.py
    ├── app.py
    ├── config.py
    ├── decorators.py
    ├── routes
    │   ├── __init__.py
    │   ├── channels.py
    │   ├── health.py
    │   ├── qr.py
    │   └── slack_events.py
    ├── services.py
    └── utils.py


3. Python Code Implementation

Source code available at: https://github.com/somaz94/slack-qr-bot/tree/main/src


4. Kubernetes Deployment

Kubernetes manifests available at: https://github.com/somaz94/slack-qr-bot/tree/main/k8s


5. GitLab CI/CD Pipeline

Automated Build and Deployment:



Usage Methods


1. Calling from Jenkins

You can automatically send QR codes after APK builds in Jenkins pipelines.



Note: Change apk_url to the path where you upload APK files. Other values like channel, build_number, and POST address are all examples.


2. Calling with curl



Note: Both channel name and channel ID are supported.


3. Testing with Swagger UI

Access http://<slack-bot-url>/api-docs in your browser to interactively test all APIs:

  1. Click “Authorize” button in upper right
  2. Enter API Key
  3. Select desired API and click “Try it out”
  4. Enter parameters and click “Execute”



Execution Results

QR codes are sent to Slack channels as shown below:

Slack QR Bot Example



Local Testing Methods

Docker Build

docker build -f Dockerfile -t slack-bot:test .


Docker Run


Local Feature Testing

Health Check:

curl http://localhost:8080/health | jq


List Channels:

curl http://localhost:8080/channels | jq


Query by Channel Name:


Query by Channel ID:


Generate Custom QR Code:


Multi-Channel Transmission:


Broadcast to All Channels:



Troubleshooting

1. channel_not_found Error

Cause: Bot not added to channel

Solution:

# Execute in Slack channel
/invite @APK QR Generator

For Private channels, groups:read and groups:write permissions are required.


2. 429 Too Many Requests Error

Cause: Rate limit exceeded

Solution:


3. Slack API Temporary Failures

Automatic retry logic attempts up to 3 times (waits 2s → 4s → 8s).

If failures persist after retries, check logs:

kubectl logs -f -n slack-bots deployment/slack-qr-bot



Performance and Monitoring

Rate Limiting Policy

Endpoint Limit Purpose
Global Default 10 req/min General calls
/generate-qr 20 req/min Single channel QR generation
/generate-qr/broadcast 10 req/min Multi-channel transmission
/generate-qr/broadcast-all 5 req/min All channel transmission
/health Unlimited Health check


Structured Logging

Logs are recorded in JSON format for easy analysis in ELK Stack or Loki:

{
  "asctime": "2025-12-23 10:30:45",
  "name": "src.app",
  "levelname": "INFO",
  "message": "QR code sent successfully",
  "channel": "apk-qr-generator",
  "file_id": "F07KP4R8E9S"
}



Conclusion

This project significantly improved the mobile app deployment process.

When Jenkins builds APKs, QR codes are automatically sent to Slack channels, and testers can download apps immediately by scanning QR codes with their mobile devices.

Key Benefits:


Future Enhancements:

I hope this bot helps others working in similar environments.



References