More Related Content
Similar to Slack Integration Noida Meetup.pptx (20)
Slack Integration Noida Meetup.pptx
- 1. July 23, 2022: Slack Integration with Anypoint Platform
MuleSoft Meetups Noida
- 2. All contents © MuleSoft Inc.
Agenda
2
• Introduction
• Introduction to Slack events
• Slack Integration with Anypoint platform
• Demo
• Networking time
- 3. All contents © MuleSoft Inc.
Introductions
3
• Organizer
A SHOW OF HANDS:
Who is new to this MeetUp?
• Speaker
Shiva Sahu Jiten Chawla
- 5. All contents © MuleSoft Inc.
Slack Events API
5
The Events API is a streamlined, easy way to build apps and bots
that respond to activities in Slack. All you need is a Slack app and a
secure place for us to send your events.
● Subscribe the events you need and ignore the ones you don’t need.
● Events sent to you are directly tied to OAuth permissions as part of
slack app you have installed.
● Slack Apps using bots can subscribe to events related to the
channels or direct message conversations.
● Slack events can be used by 2 ways. Using POST http endpoint or
via socket mode which uses dynamic web sockets.
● In order to use slack events, appropriate permissions need to be
given to the slack app and its bot user.
- 6. All contents © MuleSoft Inc.
The Event Loop
6
Many apps built using the Events API will follow same abstract event
driven sequence:-
1. A user creates a circumstance that triggers an event subscription to
your app
2. The server receives a JSON payload describing the event.
3. Your server acknowledges receipt of the event
4. Your business logic decides what to do about that event
5. Your server carries out that decision
6. Members send messages to channel the bot belongs to. The message
might contain certain keywords which would enable server to
perform certain actions such as posting message to channel.
- 7. All contents © MuleSoft Inc.
Slack Authentication and Authorization
7
Slack will generate a bot token for authentication purposes. On a new
application creation it generates a slack app token having respective
permissions to perform certain operations.
● Permissions such as messages:read, messages:write, files:read,
files:write, channel:read etc have to be configured on the app for it
to allow to perform the respective operations.
● The app token and bot token will be configured on the server side
to authenticate and authorize the events coming.
● Slack continuous to ping the server in order to make sure of the
connection
- 8. All contents © MuleSoft Inc.
Slack Event Types
8
• Slack WebSocket message:-
{
"type": "hello",
"num_connections": 1,
"debug_info": {
"host": "applink-6bdc57fdcb-g2zht",
"build_number": 9,
"approximate_connection_time": 18060
},
"connection_info": {
"app_id": "AXXXXXX"
}
}
- 9. All contents © MuleSoft Inc. 9
● Slack Command Event:
{
"envelope_id": "9a210d14-cafd-4d89-a5f1-db0804c7da30",
"payload": {
"token": "34653sdgwsrfwaef",
"team_id": "TXXXXXXXX",
"team_domain": "ABC",
"channel_id": "C0XXXXX",
"channel_name": "mulesoft-status-channel",
"user_id": "UQXXXX",
"user_name": "jiten.chawla",
"command": "/get-status",
"text": "dev",
"api_app_id": "AXXXXX",
"is_enterprise_install": "false",
"response_url": "https://hooks.slack.com/commands/TXXXXX/3822351473239/DXXXXXXXXXXXX",
"trigger_id": "000000000.000000001.2cb9ee340cf14d4f997b8e25281b5cde"
},
"type": "slash_commands",
"accepts_response_payload": true
}
- 10. All contents © MuleSoft Inc.
Slack Integration with Anypoint Platform
● We will be using slash commands to trigger slack events.
● Slash commands acts as shortcut for specific actions
● For diff commands we will be interacting with anypoint platform
apis to perform different functions.
● We will be using Golang service as an event handler for slack
commands
● Slash commands are categorized in 3 types :-
○ Build In Slash commands :- They are default commands provided by slack.
Example /archive, /call
○ App Slash Commands :- They are created by developers for app. Example
Zoom has /zoom command and may more
○ Customised Slash commands :- These are commands that are for any new
app created in slack to perform specific tasks.
10
- 13. All contents © MuleSoft Inc. 13
1. User will be posting messages or commands to the channel
2. On Callback or command events, golang event listener will retrieve
information requested from anypoint platform using platform apis
3. Once details are retrieved from anypoint platform api, the message
will be posted to respective channel
4. Following operations will be performed:-
a. /get-status :- Retrieve Status for all the applications deployed in anypoint
runtime manager
b. /change-status :- Start, stop or restart the application in runtime manager
c. /get-asset-info :- Get information of all the assets from anypoint exchange
part of the business group
d. /download-asset :- Download a particular asset from anypoint exchange.
- 14. All contents © MuleSoft Inc. 14
References
● Enabling interactivity with Slash Commands | Slack
● Slack API in Go
● Events API types | Slack
● API Platform API