Slack API integration for duso. Provides webhooks and Socket Mode client.
slack = require("slack")
Post a message to a Slack incoming webhook.
Parameters:
url (string) - Webhook URL from Slackpayload (object) - Message payload (text, blocks, attachments, etc.)Returns: Boolean (true if successful)
Example:
slack.post_webhook("https://hooks.slack.com/services/...", {
text = "Hello from Duso!"
})
Create a Socket Mode client connection.
Parameters:
config (object) - Configuration:
app_token (string, required) - Slack app token (starts with xapp_)Returns: Session object
Example:
bot = slack.session({
app_token = "xapp_1234567890_..."
})
Returned by session(). Handles Socket Mode connection.
read([timeout]) - Block until an event arrives. Returns event object or nil on timeout.write(payload) - Send a reply or response.is_connected() - Check if connection is still open.close() - Close the connection.id (string) - Connection ID (UUID)slack = require("slack")
bot = slack.session({
app_token = "xapp_..."
})
print("Bot connected: " + bot.id)
while bot.is_connected() do
event = bot.read(timeout=30)
if event == nil then
continue
end
if event.type == "events_api" then
payload = event.payload
if payload.event and payload.event.type == "message" then
msg = payload.event.text
channel = payload.event.channel
print("Got message: " + msg)
// Send reply via API
fetch("https://slack.com/api/chat.postMessage", {
method = "POST",
headers = {
"Authorization" = "Bearer xoxb_...",
"Content-Type" = "application/json"
},
body = format_json({
channel = channel,
text = "Echo: " + msg
})
})
end
end
end
bot.close()
slack = require("slack")
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX"
slack.post_webhook(webhook_url, {
text = "Alert: Database backup complete",
blocks = [
{
type = "section",
text = {
type = "mrkdwn",
text = "*Backup Status*\nCompleted at " + format_time(now())
}
}
]
})