Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 2, 2022. It is now read-only.
/SlackKitPublic archive

Build Slack apps, in Swift

License

NotificationsYou must be signed in to change notification settings

pvzig/SlackKit

Repository files navigation

SlackKit

Installation

Swift Package Manager

AddSlackKit to yourPackage.swift

letpackage=Package(dependencies:[.package(url:"https://github.com/pvzig/SlackKit.git",.upToNextMinor(from:"4.6.0"))])

When built using Swift Package Manager, SlackKit includes thevapor websocket framework by default which requires libressl.

You can install it withhomebrew:brew install libressl

For additional details, see theSKRTMAPI readme.

Carthage

AddSlackKit to yourCartfile:

github "pvzig/SlackKit"

SlackKit is now using .xcframeworks. When building your dependencies with carthage, please specify a platform:carthage bootstrap --use-xcframeworks --platform macos

CocoaPods

AddSlackKit to yourPodfile:

pod 'SlackKit'

Usage

To use the library in your project import it:

import SlackKit

The Basics

Create a bot user with an API token:

import SlackKitletbot=SlackKit()bot.addRTMBotWithAPIToken("xoxb-SLACK-BOT-TOKEN")// Register for event notificationsbot.notificationForEvent(.message){(event, _)in// Your bot logic hereprint(event.message)}

or create a ready-to-launch Slack app with yourapplication’sClient ID andClient Secret:

import SlackKitletbot=SlackKit()letoauthConfig=OAuthConfig(clientID:"CLIENT_ID", clientSecret:"CLIENT_SECRET")bot.addServer(oauth: oauthConfig)

or just make calls to the Slack Web API:

import SlackKitletbot=SlackKit()bot.addWebAPIAccessWithToken("xoxb-SLACK-BOT-TOKEN")bot.webAPI?.authenticationTest(success:{(success)inprint(success)}, failure:nil)

Slash Commands

Afterconfiguring your slash command in Slack (you can also provide slash commands as part of aSlack App), create a route, response middleware for that route, and add it to a responder:

letslackkit=SlackKit()letmiddleware=ResponseMiddleware(token:"SLASH_COMMAND_TOKEN", response:SKResponse(text:"👋"))letroute=RequestRoute(path:"/hello", middleware: middleware)letresponder=SlackKitResponder(routes:[route])slackkit.addServer(responder: responder)

When a user enters that slash command, it will hit your configured route and return the response you specified.

Message Buttons

Addmessage buttons to your responses for additional interactivity.

To send messages with actions, add them to an attachment and send them using the Web API:

lethelloAction=Action(name:"hello", text:"🌎")letattachment=Attachment(fallback:"Hello World", title:"Welcome to SlackKit", callbackID:"hello_world", actions:[helloAction])slackkit.webAPI?.sendMessage(channel:"CXXXXXX", text:"", attachments:[attachment], success:nil, failure:nil)

To respond to message actions, add aRequestRoute withMessageActionMiddleware using your app’s verification token to yourSlackKitResponder:

letresponse=ResponseMiddleware(token:"SLACK_APP_VERIFICATION_TOKEN", response:SKResponse(text:"Hello, world!"))letactionRoute=MessageActionRoute(action: helloAction, middleware: response)letactionMiddleware=MessageActionMiddleware(token:"SLACK_APP_VERIFICATION_TOKEN", routes:[actionRoute])letactions=RequestRoute(path:"/actions", middleware: actionMiddleware)letresponder=SlackKitResponder(routes:[actions])slackkit.addServer(responder: responder)

OAuth

Slack hasmany different oauth scopes that can be combined in different ways. If your application does not request the proper OAuth scopes, your API calls will fail.

If you authenticate using OAuth and the Add to Slack or Sign in with Slack buttons this is handled for you.

For local development of things like OAuth, slash commands, and message buttons, you may want to use a tool likengrok.

Advanced Usage

Don’t need the whole banana? Want more control over the low-level implementation details? Use the extensible frameworks SlackKit is built on:

FrameworkDescription
SKClientWrite your own client implementation
SKRTMAPIConnect to the Slack RTM API
SKServerSpin up a server for a Slack app
SKWebAPIAccess the Slack Web API

Examples

You can find the source code for several example applicationshere.

About

Build Slack apps, in Swift

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors32


[8]ページ先頭

©2009-2026 Movatter.jp