- Build a Slack App to capture and handle Slack events. Video Part 1
- Integration with OpenAI & Azure OpenAI with support of function call, Assistant API, and Chat Completion API. Video Part 2
- Go to your Slack workspace to create an App from scratch
- Go to Your Apps >> Setting >> Basic Information >> App Credential, note down
App ID
,Verification Token
- Go to OAuth & Permissions
- Under Scopes >> Bot Token Scopes, add/remove based on what lambda event handler logic performs, E.g.
app_mention:read
,channels:history
,groups:history
,im:history
,chat:write
- Refer: Slack Scope List for Bot Token
- Click Install to Workspace and note down
Bot User OAuth Token
- Under Scopes >> Bot Token Scopes, add/remove based on what lambda event handler logic performs, E.g.
- Go to App Home >> Show Tabs >> messages tab, toggle on and tick Allow users to send Slash commands and messages from the messages tab.
- Configure various TF vars as needed
- Run
terraform init
,plan
andapply
- Note down TF output
msg_receiver_lambda_function_url
- Go to the created Slack App >> Event Subscriptions >> Enable Events, toggle on & input
msg_receiver_lambda_function_url
into Request URL - Go to Subscribe to Bot Event >> Add Bot User Event, add event types you would like to receive and handle. E.g.
app_mention
,message.group
,message.channel
,message.im
- Refer: Slack Event List
- Go to OAuth & Permissions, click Reinstall to Workspace
- EITHER Add this Slack App to Channels you would like to monitor
- OR message this Slack App directly
- (Usage also depends on this Slack App's Event Subscription and Permission setup)
- Refer to sample_handler() as an example
- Create additional handler logic e.g.
xxx_handler.py
- Update
lambda_function.py
- Create additional handler logic e.g.
- You may implement more function call in
openai_handler.py
oraz_openai_handler.py
- Refer to llm_tools.py as an example
-
Slack App (create on Slack)
- To emit Slack event
- (optional) To perform additional work as part of customizable event handling logic
-
Lambda Event Recevier (Setup on AWS)
- As destination of Slack event subscription
- Using lambda function url as endpoint
- Push Slack events to an SQS for further handling
- Verify initial Slack event subscription challenge
- Includes necessary IAM role, policy and etc
-
SQS (Setup on AWS)
- SQS to store received Slack events
- Trigger Lambda handler for processing
- Includes necessary IAM role, policy, kms and etc
-
Lambda Event Handler (Setup on AWS)
- Process logic to handle Slack events from SQS
- Ex1.
sample_handler
: echo the message received - Ex2.
tag_user_handler
: Extract User emails in slack message, find the Slack user, and send a reply message to @user
- Ex1.
- Handling logic should be customized based on needs
- Process logic to handle Slack events from SQS
-
DynamoDB for mapping of Slack thread and OpenAI Assistant thread (Setup on AWS)
- Store the OpenAI assistant thread id for each Slack thread
- Only needed for OpenAI Assistant API handler
-
DynamoDB to keep thread history (Setup on AWS)
- As chat completion API requires full message history for each API call, the DDB keeps the messages in each thread
- Only for OpenAI Chat Completion API handler
- Replace deprecating Slack verification token with signning secret
- Further protection for lambda function url and alternative setup to expose lambda
- Add handler for LLM self hosted on Ollama