-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
209 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Dart | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: dart-lang/setup-dart@v1 | ||
|
||
- name: Install dependencies | ||
run: dart pub get | ||
|
||
- name: Verify formatting | ||
run: dart format --output=none --set-exit-if-changed . | ||
|
||
- name: Analyze project source | ||
run: dart analyze | ||
|
||
- name: Run tests | ||
run: dart test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
# Files and directories created by pub | ||
.dart_tool/ | ||
.packages | ||
# Remove the following pattern if you wish to check in your lock file | ||
|
||
# Omit commiting pubspec.lock for library packages: | ||
# https://dart.dev/guides/libraries/private-files#pubspeclock | ||
pubspec.lock | ||
|
||
# Conventional directory for build outputs | ||
build/ | ||
|
||
# Directory created by dartdoc | ||
doc/api/ | ||
|
||
.vscode/ | ||
.idea/ | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,69 @@ | ||
# slack_notifier | ||
|
||
A simple wrapper to post messages from external sources into Slack. | ||
Dart wrapper for posting messages to Slack using Incoming Webhooks. | ||
|
||
[![Build Status](https://travis-ci.com/javoeria/slack-dart.svg?branch=master)](https://travis-ci.com/javoeria/slack-dart) | ||
[![pub package](https://img.shields.io/pub/v/slack_notifier.svg)](https://pub.dartlang.org/packages/slack_notifier) | ||
[![Build Status](https://github.com/javoeria/slack-dart/actions/workflows/dart.yml/badge.svg?branch=master)](https://github.com/javoeria/slack-dart/actions/workflows/dart.yml) | ||
[![pub package](https://img.shields.io/pub/v/slack_notifier.svg)](https://pub.dev/packages/slack_notifier) | ||
|
||
## Usage | ||
## Getting Started | ||
|
||
Incoming Webhooks are a simple way to post messages from apps into Slack. Creating an Incoming Webhook gives you a unique URL to which you send a JSON payload with the message text and some options. You can use all the usual [formatting](https://api.slack.com/reference/surfaces/formatting) and [layout blocks](https://api.slack.com/messaging/composing/layouts) with Incoming Webhooks to make the messages stand out. | ||
|
||
To get the WEBHOOK_URL you need: | ||
|
||
To use this package, your workspace needs to have a Webhook URL. | ||
If you don't have it, follow the instructions [here](https://api.slack.com/messaging/webhooks). | ||
1. Create a Slack app (if you don't have one already) | ||
2. Enable Incoming Webhooks | ||
3. Create an Incoming Webhook | ||
4. Use your Incoming Webhook URL to post a message | ||
|
||
Read more about webhooks [here](https://api.slack.com/messaging/webhooks). | ||
|
||
## Usage | ||
|
||
The `SlackNotifier` class has only one method, with optional parameters to customize your messages. | ||
It supports [block kit](https://api.slack.com/reference/block-kit). | ||
This method posts a message to a public channel, private channel, or direct message/IM channel. | ||
|
||
```dart | ||
Future<String> send( | ||
String text, { | ||
String? channel, // Channel, private group, or IM channel name to send message to. | ||
String? iconEmoji, // Emoji to use as the icon for this message. | ||
String? iconUrl, // URL to an image to use as the icon for this message. | ||
String? username, // Set your bot's user name. | ||
List<Block>? blocks, // Blocks that can be combined to create interactive messages. | ||
List<Attachment>? attachments, // Attachments that can be added as secondary content. | ||
}); | ||
final slack = SlackNotifier('WEBHOOK_URL'); | ||
slack.send( | ||
'Hello world', | ||
channel: 'general', | ||
iconEmoji: ':chart_with_upwards_trend:', | ||
iconUrl: 'https://picsum.photos/48/48', | ||
username: 'My Bot', | ||
blocks: [SectionBlock(text: 'Hello world')], | ||
attachments: [Attachment(pretext: 'pre-hello', text: 'text-world')], | ||
); | ||
``` | ||
|
||
And the message will look like this: | ||
The usage of the `text` field changes depending on whether you're using `blocks`. If you are using `blocks`, this is used as a fallback string to display in notifications. If you aren't, this is the main body text of the message. It can be formatted as plain text, or with `mrkdwn`. | ||
|
||
![example](https://a.slack-edge.com/80588/img/integrations/incoming_webhook_example1.png) | ||
## Blocks | ||
|
||
Blocks are a series of components that can be combined to create visually rich and compellingly interactive messages. [Block Kit](https://api.slack.com/reference/block-kit) can make your app's communication clearer while also giving you consistent opportunity to interact with and assist users. | ||
|
||
- `ActionsBlock` A block that is used to hold multiple interactive elements. | ||
- `ContextBlock` Used for contextual info, which can include both images and text. | ||
- `DividerBlock` A content divider used to visually separate pieces of info inside of a message. | ||
- `FileBlock` Used with remote files to display info about the attached files. | ||
- `HeaderBlock` A larger-sized text block used as a header. | ||
- `ImageBlock` A simple image block, designed to make those cat photos really pop. | ||
- `InputBlock` A block that collects information from users in a multitude of ways. | ||
- `SectionBlock` Display text or combine text with interactive elements and images. | ||
- `VideoBlock` A block designed to display those cool cat videos. | ||
|
||
Individual blocks can be stacked together to create complex visual layouts. | ||
|
||
```dart | ||
var blocks = [ | ||
HeaderBlock(text: 'Onboarding'), | ||
SectionBlock(text: 'Example message for engaging new users.'), | ||
DividerBlock(), | ||
SectionBlock(text: "Hey there :wave: I'm *TaskBot*. I'm here to help you create and manage tasks in Slack."), | ||
ImageBlock( | ||
imageUrl: 'https://api.slack.com/img/blocks/bkb_template_images/onboardingComplex.jpg', | ||
altText: 'image1', | ||
title: 'image1', | ||
), | ||
]; | ||
slack.send('Onboarding', channel: 'general', blocks: blocks); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
name: slack_notifier | ||
description: A simple wrapper to post messages from external sources into Slack. | ||
version: 1.2.0 | ||
description: A simple wrapper for posting messages to Slack using Incoming Webhooks. | ||
version: 1.3.0 | ||
homepage: https://github.com/javoeria/slack-dart | ||
|
||
environment: | ||
sdk: ">=2.12.0 <3.0.0" | ||
|
||
dependencies: | ||
http: ^0.13.4 | ||
http: ^0.13.5 | ||
|
||
dev_dependencies: | ||
lints: ^1.0.1 | ||
test: ^1.20.1 | ||
lints: ^2.0.1 | ||
test: ^1.24.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters