.gitignore000064400000000036144761607230006545 0ustar00/vendor/ /tests/ composer.lockREADME.md000064400000000010144761607230006024 0ustar00# slack composer.json000064400000000775144761607230007311 0ustar00{ "name": "boru/slack", "type": "library", "autoload": { "psr-4": { "boru\\slack\\": "src/" } }, "authors": [ { "name": "Daniel Hayes", "email": "dhayes@boruapps.com" } ], "require": { "boru/dhutils": "*", "boru/dhapi": "*", "palanik/wrapi": "^0.1.7" }, "repositories": [ { "type": "composer", "url": "https://satis.boruapps.com" } ] } instructions-composer.txt000064400000000311144761607230011703 0ustar00{ "require": { "boru/dhcli": "dev-master" }, "repositories": [ { "type": "composer", "url": "https://satis.boruapps.com" } ] }src/Message.php000064400000003711144761607230007444 0ustar00altText = $altText; $this->channel = $channel; $this->blocks = $blocks; } public function add($block) { $this->blocks[] = $block; } public function altText($altText=null) { if($altText === null) return $this->altText; $this->altText = $altText; return $this; } public function channel($channel=null) { if($channel === null) return $this->channel; $this->channel = $channel; return $this; } public function toArray() { return $this->blocks; } public function jsonSerialize() { return $this->toArray(); } public function __toString() { return json_encode($this->toArray()); } public static function SectionBlock($fields=[],$accessory=[]) { return new message\blocks\SectionBlock($fields,$accessory); } public static function TextBlock($text) { return new message\blocks\TextBlock($text); } public static function HeaderBlock($text) { return new message\blocks\HeaderBlock($text); } public static function DividerBlock() { return new message\blocks\DividerBlock(); } public static function ContextBlock($elements=[]) { return new message\blocks\ContextBlock($elements); } public static function Image($url, $altText) { return new message\elements\Image($url, $altText); } public static function Field($text, $emoji = false) { return new message\elements\Field($text, $emoji); } public static function Text($text, $textType="mrkdwn", $emoji = false) { return new message\elements\TextElement($text, $textType, $emoji); } }src/Slack.php000064400000002333144761607230007114 0ustar00 array( "User-Agent" => "slack-wrapi", "Authorization" => "Bearer ". $token ) ); $json = file_get_contents(__DIR__. '/api/slack.json'); $endpoints = json_decode($json, true); parent::__construct('https://slack.com/api/', $endpoints, $opts); } private static $instance; private static $token; public static function init($token) { if (!self::$instance || self::$token != $token) { self::$instance = new Slack($token); self::$token = $token; } return self::$instance; } public static function Message($channel,$altText="",$blocks = []) { $message = new Message($channel,$altText,$blocks); } public static function sendMessage($message) { $array = ["channel"=>$message->channel(), "blocks"=>json_encode($message),"text"=>$message->altText()]; //print_r($array); //exit(); return self::$instance->chat->postMessage($array); } }src/WebHook.php000064400000007375144761607230007430 0ustar00body('challenge',false); if($challenge === false) { static::emit(Response::fromError("No challenge specified",400)); } static::emit(Response::fromSuccess(["challenge"=>$challenge],200)); }); $eventCallbackHandler = function($array,$dispatcher) { $event = $dispatcher->body('event',false); if($event === false) { static::emit(Response::fromError("No event specified",400)); } $event_type = $event['type']; $handlers=0; if(isset(self::$eventHandlers[$event_type])) { foreach(self::$eventHandlers[$event_type] as $callback) { $handlers++; $callback($event,$dispatcher); } } if($handlers == 0) { static::emit(Response::fromError("No event handler for event type: ".$event_type,200)); } static::emit(Response::fromSuccess(["handlers"=>$handlers],200)); }; static::on("event",$eventCallbackHandler); static::on("event_callback",$eventCallbackHandler); $router = new Router(); $router->add(new Route('main','/',['GET','POST','PUT','HEAD'],function($api) { return WebHook::callback($api); })); $request = API::requestFromGlobals(); $api = new API($request,$router); $response = $api->process(); $response->emit(true); } /** * * @param Dispatcher $dispatcher * @return void */ public static function callback($dispatcher) { //$test = $api->body('test.val',"notset"); //return new Response(["test"=>$test],200); $type = $dispatcher->body('type',false); if($type === false) { return Response::fromError("No type specified",400); } $handlers=0; if(isset(self::$handlers[$type])) { foreach(self::$handlers[$type] as $callback) { $handlers++; $callback($dispatcher->body(),$dispatcher); } } static::emit(Response::fromSuccess(["handlers"=>$handlers],200)); } public static function on($type,$callback) { if(!isset(self::$handlers[$type])) { self::$handlers[$type] = []; } self::$handlers[$type][] = $callback; } public static function onEvent($event,$callback) { if(!isset(self::$eventHandlers[$event])) { self::$eventHandlers[$event] = []; } self::$eventHandlers[$event][] = $callback; } public static function emit($response=null) { if($response === null) { $response = static::$response; } if(!($response instanceof Response)) { if(!empty($response)) { if(is_array($response) || is_object($response)) { $response = Response::fromSuccess($response,200); } else { $response = Response::fromSuccess(["response"=>$response],200); } } else { $response = Response::fromSuccess([],200); } } $response->emit(true); exit(); } }src/api/slack.json000064400000024446144761607230010120 0ustar00{ "api.test": { "method": "GET", "path": "api.test" }, "apps.permissions.info": { "method": "GET", "path": "apps.permissions.info" }, "apps.permissions.request": { "method": "GET", "path": "apps.permissions.request" }, "apps.permissions.resources.list": { "method": "GET", "path": "apps.permissions.resources.list" }, "apps.permissions.scopes.list": { "method": "GET", "path": "apps.permissions.scopes.list" }, "apps.permissions.users.list": { "method": "GET", "path": "apps.permissions.users.list" }, "apps.permissions.users.request": { "method": "GET", "path": "apps.permissions.users.request" }, "apps.uninstall": { "method": "GET", "path": "apps.uninstall" }, "auth.revoke": { "method": "GET", "path": "auth.revoke" }, "auth.test": { "method": "GET", "path": "auth.test" }, "bots.info": { "method": "GET", "path": "bots.info" }, "channels.archive": { "method": "GET", "path": "channels.archive" }, "channels.create": { "method": "GET", "path": "channels.create" }, "channels.history": { "method": "GET", "path": "channels.history" }, "channels.info": { "method": "GET", "path": "channels.info" }, "channels.invite": { "method": "GET", "path": "channels.invite" }, "channels.join": { "method": "GET", "path": "channels.join" }, "channels.kick": { "method": "GET", "path": "channels.kick" }, "channels.leave": { "method": "GET", "path": "channels.leave" }, "channels.list": { "method": "GET", "path": "channels.list" }, "channels.mark": { "method": "GET", "path": "channels.mark" }, "channels.rename": { "method": "GET", "path": "channels.rename" }, "channels.replies": { "method": "GET", "path": "channels.replies" }, "channels.setPurpose": { "method": "GET", "path": "channels.setPurpose" }, "channels.setTopic": { "method": "GET", "path": "channels.setTopic" }, "channels.unarchive": { "method": "GET", "path": "channels.unarchive" }, "chat.delete": { "method": "GET", "path": "chat.delete" }, "chat.getPermalink": { "method": "GET", "path": "chat.getPermalink" }, "chat.meMessage": { "method": "GET", "path": "chat.meMessage" }, "chat.postEphemeral": { "method": "GET", "path": "chat.postEphemeral" }, "chat.postMessage": { "method": "GET", "path": "chat.postMessage" }, "chat.unfurl": { "method": "GET", "path": "chat.unfurl" }, "chat.update": { "method": "GET", "path": "chat.update" }, "conversations.archive": { "method": "GET", "path": "conversations.archive" }, "conversations.close": { "method": "GET", "path": "conversations.close" }, "conversations.create": { "method": "GET", "path": "conversations.create" }, "conversations.history": { "method": "GET", "path": "conversations.history" }, "conversations.info": { "method": "GET", "path": "conversations.info" }, "conversations.invite": { "method": "GET", "path": "conversations.invite" }, "conversations.join": { "method": "GET", "path": "conversations.join" }, "conversations.kick": { "method": "GET", "path": "conversations.kick" }, "conversations.leave": { "method": "GET", "path": "conversations.leave" }, "conversations.list": { "method": "GET", "path": "conversations.list" }, "conversations.members": { "method": "GET", "path": "conversations.members" }, "conversations.open": { "method": "GET", "path": "conversations.open" }, "conversations.rename": { "method": "GET", "path": "conversations.rename" }, "conversations.replies": { "method": "GET", "path": "conversations.replies" }, "conversations.setPurpose": { "method": "GET", "path": "conversations.setPurpose" }, "conversations.setTopic": { "method": "GET", "path": "conversations.setTopic" }, "conversations.unarchive": { "method": "GET", "path": "conversations.unarchive" }, "dialog.open": { "method": "GET", "path": "dialog.open" }, "dnd.endDnd": { "method": "GET", "path": "dnd.endDnd" }, "dnd.endSnooze": { "method": "GET", "path": "dnd.endSnooze" }, "dnd.info": { "method": "GET", "path": "dnd.info" }, "dnd.setSnooze": { "method": "GET", "path": "dnd.setSnooze" }, "dnd.teamInfo": { "method": "GET", "path": "dnd.teamInfo" }, "emoji.list": { "method": "GET", "path": "emoji.list" }, "files.comments.add": { "method": "GET", "path": "files.comments.add" }, "files.comments.delete": { "method": "GET", "path": "files.comments.delete" }, "files.comments.edit": { "method": "GET", "path": "files.comments.edit" }, "files.delete": { "method": "GET", "path": "files.delete" }, "files.info": { "method": "GET", "path": "files.info" }, "files.list": { "method": "GET", "path": "files.list" }, "files.revokePublicURL": { "method": "GET", "path": "files.revokePublicURL" }, "files.sharedPublicURL": { "method": "GET", "path": "files.sharedPublicURL" }, "files.upload": { "method": "GET", "path": "files.upload" }, "groups.archive": { "method": "GET", "path": "groups.archive" }, "groups.create": { "method": "GET", "path": "groups.create" }, "groups.createChild": { "method": "GET", "path": "groups.createChild" }, "groups.history": { "method": "GET", "path": "groups.history" }, "groups.info": { "method": "GET", "path": "groups.info" }, "groups.invite": { "method": "GET", "path": "groups.invite" }, "groups.kick": { "method": "GET", "path": "groups.kick" }, "groups.leave": { "method": "GET", "path": "groups.leave" }, "groups.list": { "method": "GET", "path": "groups.list" }, "groups.mark": { "method": "GET", "path": "groups.mark" }, "groups.open": { "method": "GET", "path": "groups.open" }, "groups.rename": { "method": "GET", "path": "groups.rename" }, "groups.replies": { "method": "GET", "path": "groups.replies" }, "groups.setPurpose": { "method": "GET", "path": "groups.setPurpose" }, "groups.setTopic": { "method": "GET", "path": "groups.setTopic" }, "groups.unarchive": { "method": "GET", "path": "groups.unarchive" }, "im.close": { "method": "GET", "path": "im.close" }, "im.history": { "method": "GET", "path": "im.history" }, "im.list": { "method": "GET", "path": "im.list" }, "im.mark": { "method": "GET", "path": "im.mark" }, "im.open": { "method": "GET", "path": "im.open" }, "im.replies": { "method": "GET", "path": "im.replies" }, "migration.exchange": { "method": "GET", "path": "migration.exchange" }, "mpim.close": { "method": "GET", "path": "mpim.close" }, "mpim.history": { "method": "GET", "path": "mpim.history" }, "mpim.list": { "method": "GET", "path": "mpim.list" }, "mpim.mark": { "method": "GET", "path": "mpim.mark" }, "mpim.open": { "method": "GET", "path": "mpim.open" }, "mpim.replies": { "method": "GET", "path": "mpim.replies" }, "oauth.access": { "method": "GET", "path": "oauth.access" }, "oauth.token": { "method": "GET", "path": "oauth.token" }, "pins.add": { "method": "GET", "path": "pins.add" }, "pins.list": { "method": "GET", "path": "pins.list" }, "pins.remove": { "method": "GET", "path": "pins.remove" }, "reactions.add": { "method": "GET", "path": "reactions.add" }, "reactions.get": { "method": "GET", "path": "reactions.get" }, "reactions.list": { "method": "GET", "path": "reactions.list" }, "reactions.remove": { "method": "GET", "path": "reactions.remove" }, "reminders.add": { "method": "GET", "path": "reminders.add" }, "reminders.complete": { "method": "GET", "path": "reminders.complete" }, "reminders.delete": { "method": "GET", "path": "reminders.delete" }, "reminders.info": { "method": "GET", "path": "reminders.info" }, "reminders.list": { "method": "GET", "path": "reminders.list" }, "rtm.connect": { "method": "GET", "path": "rtm.connect" }, "rtm.start": { "method": "GET", "path": "rtm.start" }, "search.all": { "method": "GET", "path": "search.all" }, "search.files": { "method": "GET", "path": "search.files" }, "search.messages": { "method": "GET", "path": "search.messages" }, "stars.add": { "method": "GET", "path": "stars.add" }, "stars.list": { "method": "GET", "path": "stars.list" }, "stars.remove": { "method": "GET", "path": "stars.remove" }, "team.accessLogs": { "method": "GET", "path": "team.accessLogs" }, "team.billableInfo": { "method": "GET", "path": "team.billableInfo" }, "team.info": { "method": "GET", "path": "team.info" }, "team.integrationLogs": { "method": "GET", "path": "team.integrationLogs" }, "team.profile.get": { "method": "GET", "path": "team.profile.get" }, "usergroups.create": { "method": "GET", "path": "usergroups.create" }, "usergroups.disable": { "method": "GET", "path": "usergroups.disable" }, "usergroups.enable": { "method": "GET", "path": "usergroups.enable" }, "usergroups.list": { "method": "GET", "path": "usergroups.list" }, "usergroups.update": { "method": "GET", "path": "usergroups.update" }, "usergroups.users.list": { "method": "GET", "path": "usergroups.users.list" }, "usergroups.users.update": { "method": "GET", "path": "usergroups.users.update" }, "users.conversations": { "method": "GET", "path": "users.conversations" }, "users.deletePhoto": { "method": "GET", "path": "users.deletePhoto" }, "users.getPresence": { "method": "GET", "path": "users.getPresence" }, "users.identity": { "method": "GET", "path": "users.identity" }, "users.info": { "method": "GET", "path": "users.info" }, "users.list": { "method": "GET", "path": "users.list" }, "users.lookupByEmail": { "method": "GET", "path": "users.lookupByEmail" }, "users.setActive": { "method": "GET", "path": "users.setActive" }, "users.setPhoto": { "method": "GET", "path": "users.setPhoto" }, "users.setPresence": { "method": "GET", "path": "users.setPresence" }, "users.profile.get": { "method": "GET", "path": "users.profile.get" }, "users.profile.set": { "method": "GET", "path": "users.profile.set" }, "views.open": { "method": "POST", "path": "views.open" }, "views.publish": { "method": "POST", "path": "views.publish" }, "views.push": { "method": "POST", "path": "views.push" }, "views.update": { "method": "POST", "path": "views.update" } } src/message/Block.php000064400000000562144761607230010537 0ustar00 $this->type]; } public function jsonSerialize() { return $this->toArray(); } public function __toString() { return json_encode($this->toArray()); } }src/message/blocks/ContextBlock.php000064400000001060144761607230013353 0ustar00elements = $elements; } public function toArray() { $array = [ 'type' => $this->type, 'elements' => $this->elements, ]; return $array; } public function add($element) { $this->elements[] = $element; return $this; } }src/message/blocks/DividerBlock.php000064400000000511144761607230013315 0ustar00 $this->type, ]; return $array; } }src/message/blocks/HeaderBlock.php000064400000000734144761607230013126 0ustar00text['type'] = "plain_text"; $this->text["text"] = $text; } public function toArray() { $array = [ 'type' => $this->type, 'text' => $this->text, ]; return $array; } }src/message/blocks/SectionBlock.php000064400000001443144761607230013340 0ustar00fields = $fields; $this->accessory = $accessory; } public function toArray() { $array = [ 'type' => $this->type, ]; if (count($this->fields) > 0) { $array['fields'] = $this->fields; } if (count($this->accessory) > 0) { $array['accessory'] = $this->accessory; } return $array; } public function addField($block) { $this->fields[] = $block; return $this; } }src/message/blocks/TextBlock.php000064400000001703144761607230012657 0ustar00text['type'] = $textType; $this->text["text"] = $text; $this->fields = $fields; $this->accessory = $accessory; } public function toArray() { $array = [ 'type' => $this->type, 'text' => $this->text, ]; if (count($this->fields) > 0) { $array['fields'] = $this->fields; } if (count($this->accessory) > 0) { $array['accessory'] = $this->accessory; } return $array; } public function addField($block) { $this->fields[] = $block; return $this; } }src/message/elements/Field.php000064400000000755144761607230012350 0ustar00text['type'] = $textType; $this->text["text"] = $text; } public function toArray() { $array = [ 'type' => $this->type, 'text' => $this->text ]; return $array; } }src/message/elements/Image.php000064400000001075144761607230012343 0ustar00image_url = $image_url; $this->alt_text = $alt_text; } public function toArray() { $array = [ 'type' => $this->type, 'image_url' => $this->image_url, 'alt_text' => $this->alt_text ]; return $array; } }src/message/elements/TextElement.php000064400000001177144761607230013562 0ustar00text = $text; $this->type = $textType; $this->emoji = $emoji; } public function toArray() { $array = [ 'type' => $this->type, 'text' => $this->text, ]; if ($this->emoji) { $array['emoji'] = $this->emoji; } return $array; } }