The following features may not be available to all Transposit Developer Platform users. Please contact Transposit support to get access to these features.
Slackbots are a great way to automate your app based on events happening in your workspace. Additionally, they are another way to interact with users in a more personal way. Create your bot easier with Transposit.
http_event
function to pass the url_verification event. This is due to Dynamic Challenges.if (http_event.parsed_body.challenge) {
return {
status_code: 200,
headers: { "Content-Type": "text/plain" },
body: http_event.parsed_body.challenge
};
}
The challenge response is a goode example of a simple webhook function. You can also create a webhook function in SQL if you prefer.
SELECT {
status_code: 200,
headers: { "Content-Type": "application/json" },
body: {
text: "Hello World, from SQL!"
}
}
Your webhook function will be called whenever the events you decide to follow occur in your workspace. Adding helper functions and other API calls before the return statement can add to the ability to customize output.
Bot users aren't just another face to post a message as, they can be used to scan for many events in the organization as a way to trigger your webhook function. Slack Events API contains a large number of events that can either happen in your workspace, or your bot is a part of to POST. Additionally, can you use App Unfurl Domains to have the event trigger upon a user posting a link from a select domain. Some common events to use are:
message.channels
message.im
app_mention
reaction_added
team_join
While Transposit makes it easy to authenticate with your Slack account, in order to act as your bot, we need to manually input the credentials of the bot. Otherwise the application will continue to execute as you.
bot.bot_access_token
, and Scope equal to the scopes you have selected in OAuth & Permissions in Slack.https://accounts.transposit.com/oauth/v2/handle-redirect
as a redirect URL.If done correctly, it should authenticate the Transposit application as the bot user, instead of you. When you post a message (if you have given your bot chat:write:bot
permissions) you should see the message posted as the bot.
You can view the data sent to your webhook from Slack in the Monitor tab, or by returning the data in the response.
({ http_event }) => {
return {
status_code: 200,
headers: { "Content-Type": "application/json" },
body: { text: JSON.stringify(http_event, null, 2) }
};
};
This gives us the full HTTP request; most of what we are interested in is in the body. Transposit parses the body according to the type specified in the headers. You'll see something like this:
"parsed_body": {
"token": "<token>",
"team_id": "XXXXXXXXX",
"api_app_id": "XXXXXXXXX",
"event": {
"type": "team_join",
"user": {
"id": "XXXXXXXXX",
"team_id": "XXXXXXXXX",
"name": "user",
"deleted": false,
"color": "ea2977",
"real_name": "name",
"tz": "America/Los_Angeles",
"tz_label": "Pacific Daylight Time",
"tz_offset": -25200,
...
"is_admin": false,
"is_owner": false,
"is_primary_owner": false,
"is_restricted": false,
"is_ultra_restricted": false,
"is_bot": false,
"is_app_user": false,
"updated": 1565992213,
"presence": "away"
},
"cache_ts": 1565992213,
"event_ts": "1565992213.000800"
},
"type": "event_callback",
"event_id": "XXXXXXXXX",
"event_time": 1565992213,
"authed_users": [
"XXXXXXXXX"
]
},
We already set this to pass the challenge back to Slack above, where we used http_event.parsed_body.challenge
. This can be done with any of the labels in the webhook.