/dart-slack

Dartlang interface to the Slack Webhook API

Primary LanguageDartCreative Commons Zero v1.0 UniversalCC0-1.0

dart-slack

Dartlang interface to the Slack Webhook API

API Documentation available on Pub

Simple Start

import 'package:slack/html/slack';
// or 
import 'package:slack/io/slack';

main() {
  Slack slack = new Slack('webhook-url');
  Message message = new Message('foo message',username:'bar-user');      
  slack.send(message);
}

Attachment Support

Minimally attachments require a 'fallback' [String], in the first field.

Attachment bugReport = new Attachment("I can't use Slack!",
   pretext: 'A Critical Bug Reported',
   text   : "I can't use Slack!",
   color  : 'danger');

Message message = new Message('Bug Report:', username: 'bugBot', attachments: [bugReport]);
slack.send(message);

Cascades

Messages, Attachments, and Fields are mostly just data containers. This means that you have a choice between setting their values in the constructor or setting them in a cascade. For example, Attachments could be defined like so:

Attachment bugReport = new Attachment("I can't use Slack!")
   ..pretext = 'A Critical Bug Reported'
   ..text   = "I can't use Slack!"
   ..color  = 'danger';

Message message = new Message('Bug Report:')
    ..username    = 'bugBot'
    ..attachments = [bugReport];
slack.send(message);