- Overview
- Prerequisites
- Getting Started
- Script Flow (Simplified)
- Main Components
- Limitations / Known Issues
- Coming Up Next
This Python script acts as an integration between:
- OpenAI's GPT-4 for ticket Classification and Summarization/Extraction
- A Slack bot via Model Context Protocol (MCP) to post messages into the correct Slack channel
β οΈ Disclaimer:
This is a basic example demonstrating how to integrate Slack with the MCP server.
This example is provided in two formats:
- Python script (
.py) - Jupyter Notebook (
.ipynb)
Choose the format that best suits your workflow (e.g., local development or use in Jupyter/Google Colab), and download the respective file.
The goal of this application is to automate support ticket handling. It simplifies operations by:
- Understanding support issues using AI
- Classifying them accurately
- Posting structured information to relevant Slack channels for quicker resolution
Before you begin, make sure you have the following set up:
- β A Slack account and a dedicated Slack channel
- β An OpenAI GPT account
To set up your Slack environment, follow the instructions provided here:
π Slack Integration Setup Guide
Make sure to add your slack app into your desired channel. In my case, i named my slack-app as TicketClassification and added to 5 channel.

- Python 3.8+
openaipackage- Access to OpenAI API Key
- Slack App with Bot Token
- MCP installed (
npx @modelcontextprotocol/server-slack)
- Install Python packages:
pip install mcp openai- Prepare
config.jsonfile with the following structure (If Slack channel is configured differently, please note the next step):
{
"OPENAI_API_KEY": "your-api-key",
"SLACK_BOT_TOKEN": "xoxb-your-token",
"SLACK_TEAM_ID": "Txxxxxx",
"SLACK_CHANNELID_CHANNELMOBILE": "Cxxxx01",
"SLACK_CHANNELID_CHANNELWEB": "Cxxxx02",
"SLACK_CHANNELID_SERVICEPAYMENT": "Cxxxx03",
"SLACK_CHANNELID_SERVICEPROVISIONING": "Cxxxx04",
"SLACK_CHANNELID_ALL": "Cxxxx99"
}- (Optional) Channel options was hardcoded, so if you want to change the channel name, you can configure in the JSON file above, and also change some of codes to meet you expectation:
On the Initialization
# Extract values from the config dictionary
OPENAI_API_KEY = config["OPENAI_API_KEY"]
SLACK_BOT_TOKEN = config["SLACK_BOT_TOKEN"]
SLACK_TEAM_ID = config["SLACK_TEAM_ID"]
SLACK_CHANNELID_CHANNELMOBILE = config["SLACK_CHANNELID_CHANNELMOBILE"]
SLACK_CHANNELID_CHANNELWEB = config["SLACK_CHANNELID_CHANNELWEB"]
SLACK_CHANNELID_SERVICEPAYMENT = config["SLACK_CHANNELID_SERVICEPAYMENT"]
SLACK_CHANNELID_SERVICEPROVISIONING = config["SLACK_CHANNELID_SERVICEPROVISIONING"]
SLACK_CHANNELID_ALL = config["SLACK_CHANNELID_ALL"]On the prompt
classificationQuery = [{
"role": "user",
"content": f"""You are a customer support classifier assistant.
Your task is to classify the following ticket message into one of these five categories:
Categories:
1. channel-mobile β Issues related to mobile applications or mobile platforms.
2. channel-web β Issues related to websites or web interfaces.
3. service-payment β Issues related to billing, payment transactions, or refunds.
4. service-provisioning β Issues related to service activation, account setup, or access provisioning.
5. unknown β If the issue doesn't clearly fit any of the above categories.
Instructions:
- Return only the category name, do not change the categories name provided above
- Be as precise as possible. Do not guess if the message is unclear β use "unknown".
---
Ticket message:
"{ticket_message}"
Category:"""
}]On the post_message
# Choose Slack channel based on classification result
if classification == "channel-mobile":
channel_id = SLACK_CHANNELID_CHANNELMOBILE
elif classification == "channel-web":
channel_id = SLACK_CHANNELID_CHANNELWEB
elif classification == "service-payment":
channel_id = SLACK_CHANNELID_SERVICEPAYMENT
elif classification == "service-provisioning":
channel_id = SLACK_CHANNELID_SERVICEPROVISIONING
else:
channel_id = SLACK_CHANNELID_ALL # Fallback/default channelpython mcp_slack_client.pyFollow the prompts:
- Enter the ticket message

- Let GPT-4 summarize and classify it
- The script will post to the right Slack channel

graph TD
A[Start] --> B[Load config.json]
B --> C[Connect to MCP Server]
C --> D[Input: Ticket Message]
D --> E[Summarize with OpenAI GPT-4]
E --> F[Classify Summary]
F --> G[Select Slack Channel]
G --> H[Post Message to Slack]
H --> I[Done / Await new input]
This class encapsulates everything:
- OpenAI client setup
- MCP session connection
- Ticket summarization and classification
- Slack message posting
Uses GPT-4 to extract:
raw_ticket_message: The full user messagepayment_channel: Method used, like card, wallet, etc.package_detail: Any plan/package mentionedtimestamp: When issue occurred (if stated)
Classifies the message into one of:
channel-mobilechannel-webservice-paymentservice-provisioningunknown
Selects Slack channel based on classification and posts the summary.
- The classification depends on GPT-4's interpretation, which may vary.
- Customize the channel name and classification to suit your specific needs.
- For production use, a more comprehensive scenario handling mechanism is required. This example is intended for demonstration purposes only.
- Consider integrating ticket-related messages directly with your existing ticketing or logging systems (e.g., Grafana, Remedy, or Jira).
- Alerts are triggered directly from Grafana (integrated as an input source for ticket generation).
- Integrates with the file system logs to fetch relevant logs based on the detected scenario
(e.g., payment-related issues will automatically retrieve logs from the payment service).