This repository has been archived by the owner on Mar 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
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
7 changed files
with
167 additions
and
0 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,23 @@ | ||
library slack_html; | ||
|
||
import 'dart:html'; | ||
import 'package:slack/src/slacksrc.dart'; | ||
export 'package:slack/src/slacksrc.dart'; | ||
|
||
|
||
/** | ||
* Posts a Slack message to the properly authenticated Slack token. | ||
* The messages will go to whatever channel the token was set up for. | ||
*/ | ||
send(Message m) { | ||
String outurl = 'https://' + team + '.slack.com/services/hooks/incoming-webhook?token=' + token; | ||
String payload = m.toString(); | ||
HttpRequest.postFormData(outurl,{'payload' : payload}); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
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,16 @@ | ||
library slack_io; | ||
|
||
import 'package:http/http.dart' as http; | ||
import 'package:slack/src/slacksrc.dart'; | ||
export 'package:slack/src/slacksrc.dart'; | ||
|
||
|
||
/** | ||
* Posts a Slack message to the properly authenticated Slack token. | ||
* The messages will go to whatever channel the token was set up for. | ||
*/ | ||
send(Message m) { | ||
String outurl = 'https://' + team + '.slack.com/services/hooks/incoming-webhook?token=' + token; | ||
String payload = m.toString(); | ||
http.post(outurl, body: {'payload' : payload}); | ||
} |
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,73 @@ | ||
import 'dart:convert'; | ||
|
||
String token, team; | ||
|
||
// A message passed between your app and slack. | ||
class Message { | ||
// Basic message vars | ||
String text; | ||
String username; | ||
String icon_url; | ||
String icon_emoji; | ||
|
||
/* | ||
* Any number of attachments | ||
* can be added to the message | ||
*/ | ||
List <Attachment> attachments; | ||
|
||
String toString() { | ||
Map message = new Map(); | ||
|
||
if (text != null) | ||
message['text'] = text; | ||
|
||
if (username != null) | ||
message['username'] = username; | ||
|
||
if (icon_url != null) | ||
message['icon_url'] = icon_url; | ||
|
||
if (icon_emoji != null) | ||
message['icon_emoji'] = icon_emoji; | ||
|
||
if (attachments != null) { | ||
List attached_maps = []; | ||
for (Attachment a in attachments) | ||
attached_maps.add(a.toMap()); | ||
message['attachments'] = attached_maps; | ||
} | ||
return JSON.encoder.convert(message); | ||
} | ||
} | ||
|
||
class Attachment { | ||
String fallback; // Required | ||
String pretext; | ||
String text; | ||
String color; // 'good', 'warning', 'danger' or hex. | ||
|
||
Map<String,String> fields; | ||
|
||
String toString() { | ||
return JSON.encoder.convert(this.toMap()); | ||
} | ||
|
||
Map toMap() { | ||
Map attachment = new Map() | ||
..['fallback'] = fallback; | ||
|
||
if (pretext != null) | ||
attachment['pretext'] = pretext; | ||
if (text != null) | ||
attachment['text'] = text; | ||
if (color != null) | ||
attachment['color'] = color; | ||
|
||
if (fields != null) | ||
attachment['fields'] = fields; | ||
|
||
return attachment; | ||
} | ||
|
||
} |
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,11 @@ | ||
name: slack | ||
version: 1.0.0 | ||
author: Paul VanKeuren <[email protected]> | ||
description: |- | ||
Package for accessing and utilizing the Slack webhook API. | ||
Currently only works for 'incoming webhooks' | ||
homepage: www.google.com/+PaulVanKeuren | ||
dependencies: | ||
http: any | ||
dev_dependencies: | ||
browser: any |
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,16 @@ | ||
import 'package:slack/slack_html.dart'; | ||
|
||
|
||
main() { | ||
token = 'oaV4CYX5OLlfwO3gciyhBxB8'; | ||
team = 'cou'; | ||
|
||
Message m = new Message() | ||
..username = 'Street Spirit' | ||
..text = 'I am a spirit!' | ||
..icon_url = 'http://childrenofur.com/assets/street_spirit.png'; | ||
|
||
|
||
send(m); | ||
print(m); | ||
} |
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,16 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>test_html</title> | ||
</head> | ||
|
||
<body> | ||
<p id="text"></p> | ||
<script type="application/dart" src="test_html.dart"></script> | ||
<!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' --> | ||
<script src="packages/browser/dart.js"></script> | ||
</body> | ||
</html> |
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,12 @@ | ||
import 'package:slack/slack_io.dart'; | ||
|
||
main() { | ||
token = 'oaV4CYX5OLlfwO3gciyhBxB8'; | ||
team = 'cou'; | ||
|
||
Message m = new Message() | ||
..username = 'Street Spirit' | ||
..text = 'I am a spirit!' | ||
..icon_url = 'http://childrenofur.com/assets/street_spirit.png'; | ||
print(send(m)); | ||
} |