├── .altax
├── .gitignore
├── composer.json
└── config.php
├── .gitignore
├── dev
├── locale
│ └── en.yml
├── js
│ └── admin
│ │ ├── Gulpfile.js
│ │ ├── package.json
│ │ ├── src
│ │ ├── main.js
│ │ ├── addNotifySettingsPage.js
│ │ └── components
│ │ │ ├── GitterSettingsModal.js
│ │ │ ├── SlackSettingsModal.js
│ │ │ ├── HipChatSettingsModal.js
│ │ │ ├── TestConnectorsModal.js
│ │ │ └── NotifySettingsPage.js
│ │ └── dist
│ │ └── extension.js
├── src
│ ├── Interfaces
│ │ └── ConnectorInterface.php
│ ├── Connectors
│ │ ├── Connector.php
│ │ ├── HipChatConnector.php
│ │ ├── GitterConnector.php
│ │ └── SlackConnector.php
│ ├── ApiRoutes.php
│ ├── Messages
│ │ ├── DiscussionWasDeletedMessage.php
│ │ ├── PostWasPostedMessage.php
│ │ ├── DiscussionWasStartedMessage.php
│ │ ├── PostWasDeletedMessage.php
│ │ ├── PostWasHiddenMessage.php
│ │ └── Message.php
│ ├── Extension.php
│ ├── Listeners
│ │ ├── AddClientAssets.php
│ │ ├── PostWasHiddenListener.php
│ │ ├── PostWasPostedListener.php
│ │ ├── DiscussionWasDeletedListener.php
│ │ ├── DiscussionWasStartedListener.php
│ │ ├── PostWasDeletedListener.php
│ │ └── NotificationListener.php
│ └── Api
│ │ └── ConnectorTest.php
├── composer.json
├── bootstrap.php
├── flarum.json
└── less
│ └── admin
│ └── extension.less
├── dist
└── flarum-notify.zip
├── composer.json
├── readme.md
└── LICENSE
/.altax/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor
2 | node_modules
--------------------------------------------------------------------------------
/dev/locale/en.yml:
--------------------------------------------------------------------------------
1 | slack:
2 | # hello_world: "Hello, world!"
3 |
--------------------------------------------------------------------------------
/dist/flarum-notify.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/moay/flarum-notify/HEAD/dist/flarum-notify.zip
--------------------------------------------------------------------------------
/.altax/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "require": {
3 | "alchemy/zippy": "^0.2.1",
4 | "windwalker/filesystem": "^2.1"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/dev/js/admin/Gulpfile.js:
--------------------------------------------------------------------------------
1 | var gulp = require('flarum-gulp');
2 |
3 | gulp({
4 | modules: {
5 | 'notify': 'src/**/*.js'
6 | }
7 | });
8 |
--------------------------------------------------------------------------------
/dev/js/admin/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "devDependencies": {
4 | "gulp": "^3.8.11",
5 | "flarum-gulp": "^0.1.0"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/dev/js/admin/src/main.js:
--------------------------------------------------------------------------------
1 | import addNotifySettingsPage from 'notify/addNotifySettingsPage';
2 |
3 | app.initializers.add('notify', app => {
4 | addNotifySettingsPage();
5 | });
6 |
--------------------------------------------------------------------------------
/dev/src/Interfaces/ConnectorInterface.php:
--------------------------------------------------------------------------------
1 | settings = $settings;
9 | $this->setup();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "root/flarum-notify",
3 | "description": "Get notified about forum activity via Slack, Hipchat or Gitter.",
4 | "license": "MIT",
5 | "authors": [
6 | {
7 | "name": "moay",
8 | "email": "mv@moay.de"
9 | }
10 | ],
11 | "require": {}
12 | }
13 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # flarum-slack
2 |
3 | Simple notifications for Flarum. Get notified about forum activities via Slack, HipChat or Gitter.
4 |
5 | ## DEPRECATED
6 |
7 | Sadly, I didn't find the time to update the repo for newer flarum versions. But manelizzard continued the work, please use [his repo](https://github.com/manelizzard/flarum-notify).
8 |
--------------------------------------------------------------------------------
/dev/bootstrap.php:
--------------------------------------------------------------------------------
1 | 0.1.0-beta.2"
15 | },
16 | "icon": {
17 | "name": "bell",
18 | "backgroundColor": "#640049",
19 | "color": "#fff"
20 | }
21 | }
--------------------------------------------------------------------------------
/dev/src/ApiRoutes.php:
--------------------------------------------------------------------------------
1 | listen(RegisterApiRoutes::class, [$this, 'addRoutes']);
10 | }
11 |
12 | /**
13 | * Registeres the api routes for the extension
14 | * @param RegisterApiRoutes $event
15 | */
16 | public function addRoutes(RegisterApiRoutes $event)
17 | {
18 | $event->get('/notify/test/{connector}', 'notify.test', 'moay\FlarumNotify\Api\ConnectorTest');
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/dev/less/admin/extension.less:
--------------------------------------------------------------------------------
1 | .NotifySettingsTable{
2 | td{
3 | padding:5px;
4 |
5 | &:first-child{
6 | padding-right:20px;
7 | font-weight:700;
8 | }
9 | }
10 | }
11 | .NotifySettingsButton.rounded{
12 | border-radius:100px;
13 | height:30px;
14 | width:30px;
15 | position:relative;
16 |
17 | .icon{
18 | margin-left:-7px;
19 | margin-top:-1px;
20 | display:block;
21 | }
22 |
23 | &.texty{
24 | width:auto;
25 | margin-left:5px;
26 | padding-top:5px;
27 | }
28 | }
29 |
30 | .TestConnectorsModal{
31 | .statusMessage{
32 | width:100%;
33 | text-align: center;
34 | font-size:16px;
35 | }
36 | }
--------------------------------------------------------------------------------
/dev/src/Messages/DiscussionWasDeletedMessage.php:
--------------------------------------------------------------------------------
1 | discussion = $discussion;
9 | $this->prepareMessage();
10 | }
11 |
12 | /**
13 | * Prepares the message which should be sent to the Connectors
14 | * @return void
15 | */
16 | function prepareMessage(){
17 | $this->title = 'Discussion deleted';
18 | $this->message = 'Discussion #' . $this->discussion->id . ' ('.$this->discussion->title.') has been deleted';
19 | $this->short = 'Discussion deleted';
20 | $this->color = 'red';
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/dev/js/admin/src/addNotifySettingsPage.js:
--------------------------------------------------------------------------------
1 | import { extend } from 'flarum/extend';
2 | import AdminNav from 'flarum/components/AdminNav';
3 | import AdminLinkButton from 'flarum/components/AdminLinkButton';
4 |
5 | import NotifySettingsPage from 'notify/components/NotifySettingsPage';
6 |
7 | export default function() {
8 |
9 | app.routes.notify = {path: '/notify', component: NotifySettingsPage.component()};
10 |
11 | app.extensionSettings.notify = () => m.route(app.route('notify'));
12 |
13 | extend(AdminNav.prototype, 'items', items => {
14 | items.add('notify', AdminLinkButton.component({
15 | href: app.route('notify'),
16 | icon: 'bell',
17 | children: 'Notify',
18 | description: 'Manage your notifications to Slack, Hipchat and Gitter.'
19 | }));
20 | });
21 | }
22 |
--------------------------------------------------------------------------------
/dev/src/Extension.php:
--------------------------------------------------------------------------------
1 | subscribe('moay\FlarumNotify\Listeners\AddClientAssets');
11 | $events->subscribe('moay\FlarumNotify\Listeners\PostWasPostedListener');
12 | $events->subscribe('moay\FlarumNotify\Listeners\PostWasHiddenListener');
13 | $events->subscribe('moay\FlarumNotify\Listeners\PostWasDeletedListener');
14 | $events->subscribe('moay\FlarumNotify\Listeners\DiscussionWasStartedListener');
15 | $events->subscribe('moay\FlarumNotify\Listeners\DiscussionWasDeletedListener');
16 |
17 | // Add API routes
18 | $events->subscribe('moay\FlarumNotify\ApiRoutes');
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/dev/src/Messages/PostWasPostedMessage.php:
--------------------------------------------------------------------------------
1 | post = $post;
9 | $this->prepareMessage();
10 | }
11 |
12 |
13 | /**
14 | * Prepares the message which should be sent to the Connectors
15 | * @return void
16 | */
17 | function prepareMessage(){
18 | $this->author = $this->post->user;
19 | $this->message = 'added a new post to discussion #' . $this->post->discussion->id . ' ('.$this->post->discussion->title.')';
20 | $this->short = 'New post';
21 |
22 | $this->addLinkToParse('@'.$this->author->username, app('flarum.config')['url']."/u/{$this->author->id}");
23 | $this->addLinkToParse('discussion #'.$this->post->discussion->id, app('flarum.config')['url']."/d/{$this->post->discussion->id}");
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/dev/src/Messages/DiscussionWasStartedMessage.php:
--------------------------------------------------------------------------------
1 | discussion = $discussion;
9 | $this->prepareMessage();
10 | }
11 |
12 |
13 | /**
14 | * Prepares the message which should be sent to the Connectors
15 | * @return void
16 | */
17 | function prepareMessage(){
18 | $this->author = $this->discussion->startUser;
19 | $this->message = 'started discussion #' . $this->discussion->id . ' ('.$this->discussion->title.')';
20 | $this->short = 'New post';
21 | $this->color = 'green';
22 |
23 | $this->addLinkToParse('@'.$this->author->username, app('flarum.config')['url']."/u/{$this->author->id}");
24 | $this->addLinkToParse('discussion #'.$this->discussion->id, app('flarum.config')['url']."/d/{$this->discussion->id}");
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/dev/src/Messages/PostWasDeletedMessage.php:
--------------------------------------------------------------------------------
1 | post = $post;
9 | $this->prepareMessage();
10 | }
11 |
12 |
13 | /**
14 | * Prepares the message which should be sent to the Connectors
15 | * @return void
16 | */
17 | function prepareMessage(){
18 | $this->title = 'Post deleted';
19 | $this->message = '@'.$this->post->user->username.'\'s post was deleted from discussion #' . $this->post->discussion->id . ' ('.$this->post->discussion->title.')';
20 | $this->short = 'Post deleted';
21 | $this->color = 'red';
22 |
23 | $this->addLinkToParse('@'.$this->post->user->username, app('flarum.config')['url']."/u/{$this->post->user->id}");
24 | $this->addLinkToParse('discussion #'.$this->post->discussion->id, app('flarum.config')['url']."/d/{$this->post->discussion->id}");
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/dev/src/Messages/PostWasHiddenMessage.php:
--------------------------------------------------------------------------------
1 | post = $post;
9 | $this->prepareMessage();
10 | }
11 |
12 |
13 | /**
14 | * Prepares the message which should be sent to the Connectors
15 | * @return void
16 | */
17 | function prepareMessage(){
18 | $this->title = 'Post hidden';
19 | $this->message = '@'.$this->post->user->username.'\'s post was hidden from discussion #' . $this->post->discussion->id . ' ('.$this->post->discussion->title.')';
20 | $this->short = 'Post hidden';
21 | $this->color = 'orange';
22 |
23 | $this->addLinkToParse('@'.$this->post->user->username, app('flarum.config')['url']."/u/{$this->post->user->id}");
24 | $this->addLinkToParse('discussion #'.$this->post->discussion->id, app('flarum.config')['url']."/d/{$this->post->discussion->id}");
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/dev/src/Listeners/AddClientAssets.php:
--------------------------------------------------------------------------------
1 | listen(RegisterLocales::class, [$this, 'addLocale']);
12 | $events->listen(BuildClientView::class, [$this, 'addAssets']);
13 | }
14 |
15 | public function addLocale(RegisterLocales $event)
16 | {
17 | $event->addTranslations('en', __DIR__.'/../../locale/en.yml');
18 | }
19 |
20 | public function addAssets(BuildClientView $event)
21 | {
22 | $event->adminAssets([
23 | __DIR__.'/../../js/admin/dist/extension.js',
24 | __DIR__.'/../../less/admin/extension.less'
25 | ]);
26 |
27 | $event->adminBootstrapper('notify/main');
28 |
29 | $event->adminTranslations([
30 | // 'slack.hello_world'
31 | ]);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/dev/src/Messages/Message.php:
--------------------------------------------------------------------------------
1 | linksToParse[$string] = $url;
19 | }
20 |
21 | public function getAuthor(){
22 | return $this->author;
23 | }
24 |
25 | public function getMessage(){
26 | return $this->message;
27 | }
28 |
29 | public function getShort(){
30 | return $this->short;
31 | }
32 |
33 | public function getTitle(){
34 | return $this->title;
35 | }
36 |
37 | public function getColor(){
38 | return $this->color;
39 | }
40 |
41 | public function getLinksToParse(){
42 | return $this->linksToParse;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 moay
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/dev/src/Listeners/PostWasHiddenListener.php:
--------------------------------------------------------------------------------
1 | listen(PostWasHidden::class, [$this, 'sendMessage']);
13 | }
14 |
15 | /**
16 | * Sends a message via all of the enable connectors
17 | * @param PostWasHidden $event
18 | * @return void
19 | */
20 | public function sendMessage(PostWasHidden $event)
21 | {
22 | if($this->shouldTrigger($event)){
23 | $message = new PostWasHiddenMessage($event->post);
24 |
25 | foreach($this->getConnectorsToNotify() as $connector){
26 | $connector->send($message);
27 | }
28 | }
29 | }
30 |
31 | /**
32 | * Checks wether or not this listener should send a notification for this event
33 | * @param PostWasHidden $event
34 | * @return boolean
35 | */
36 | public function shouldTrigger(PostWasHidden $event){
37 | if($this->settings->get('notify.events.post_hidden') === '1'){
38 | return true;
39 | }
40 | return false;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/dev/src/Listeners/PostWasPostedListener.php:
--------------------------------------------------------------------------------
1 | listen(PostWasPosted::class, [$this, 'sendMessage']);
13 | }
14 |
15 | /**
16 | * Sends a message via all of the enable connectors
17 | * @param PostWasPosted $event
18 | * @return void
19 | */
20 | public function sendMessage(PostWasPosted $event)
21 | {
22 | if($this->shouldTrigger($event)){
23 | $message = new PostWasPostedMessage($event->post);
24 |
25 | foreach($this->getConnectorsToNotify() as $connector){
26 | $connector->send($message);
27 | }
28 | }
29 | }
30 |
31 | /**
32 | * Checks wether or not this listener should send a notification for this event
33 | * @param PostWasPosted $event
34 | * @return boolean
35 | */
36 | public function shouldTrigger(PostWasPosted $event){
37 | if($this->settings->get('notify.events.new_post') === '1'
38 | && $event->post->discussion->posts()->count() > 1){
39 | return true;
40 | }
41 | return false;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/dev/src/Listeners/DiscussionWasDeletedListener.php:
--------------------------------------------------------------------------------
1 | listen(DiscussionWasDeleted::class, [$this, 'sendMessage']);
13 | }
14 |
15 | /**
16 | * Sends a message via all of the enable connectors
17 | * @param PostWasPosted $event
18 | * @return void
19 | */
20 | public function sendMessage(DiscussionWasDeleted $event)
21 | {
22 | if($this->shouldTrigger($event)){
23 | $message = new DiscussionWasDeletedMessage($event->discussion);
24 |
25 | foreach($this->getConnectorsToNotify() as $connector){
26 | $connector->send($message);
27 | }
28 | }
29 | }
30 |
31 | /**
32 | * Checks wether or not this listener should send a notification for this event
33 | * @param DiscussionWasDeleted $event
34 | * @return boolean
35 | */
36 | public function shouldTrigger(DiscussionWasDeleted $event){
37 | if($this->settings->get('notify.events.discussion_deleted') === '1'){
38 | return true;
39 | }
40 | return false;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/dev/src/Listeners/DiscussionWasStartedListener.php:
--------------------------------------------------------------------------------
1 | listen(DiscussionWasStarted::class, [$this, 'sendMessage']);
13 | }
14 |
15 | /**
16 | * Sends a message via all of the enable connectors
17 | * @param PostWasPosted $event
18 | * @return void
19 | */
20 | public function sendMessage(DiscussionWasStarted $event)
21 | {
22 | if($this->shouldTrigger($event)){
23 | $message = new DiscussionWasStartedMessage($event->discussion);
24 |
25 | foreach($this->getConnectorsToNotify() as $connector){
26 | $connector->send($message);
27 | }
28 | }
29 | }
30 |
31 | /**
32 | * Checks wether or not this listener should send a notification for this event
33 | * @param DiscussionWasStarted $event
34 | * @return boolean
35 | */
36 | public function shouldTrigger(DiscussionWasStarted $event){
37 | if($this->settings->get('notify.events.new_discussion') === '1'){
38 | return true;
39 | }
40 | return false;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/dev/src/Listeners/PostWasDeletedListener.php:
--------------------------------------------------------------------------------
1 | listen(PostWasDeleted::class, [$this, 'sendMessage']);
13 | }
14 |
15 | /**
16 | * Sends a message via all of the enable connectors
17 | * @param PostWasDeleted $event
18 | * @return void
19 | */
20 | public function sendMessage(PostWasDeleted $event)
21 | {
22 | if($this->shouldTrigger($event)){
23 | $message = new PostWasDeletedMessage($event->post);
24 |
25 | foreach($this->getConnectorsToNotify() as $connector){
26 | $connector->send($message);
27 | }
28 | }
29 | }
30 |
31 | /**
32 | * Checks wether or not this listener should send a notification for this event
33 | * @param PostWasDeleted $event
34 | * @return boolean
35 | */
36 | public function shouldTrigger(PostWasDeleted $event){
37 | if($this->settings->get('notify.events.post_deleted') === '1'
38 | && $event->post->discussion
39 | && $event->post->discussion->posts()->count() != 0){
40 | return true;
41 | }
42 | return false;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/dev/src/Listeners/NotificationListener.php:
--------------------------------------------------------------------------------
1 | settings = $settings;
15 | new HipChatConnector($this->settings);
16 | }
17 |
18 | /**
19 | * Returns all connectors that need to be notified
20 | * @return array The connectors
21 | */
22 | protected function getConnectorsToNotify(){
23 | $connectors = [];
24 | // Check for slack
25 | if($this->settings->get('notify.services.slack') && $this->settings->get('notify.slack.token') && $this->settings->get('notify.slack.channel')){
26 | $connectors[] = new SlackConnector($this->settings);
27 | }
28 | // Check for HipChat
29 | if($this->settings->get('notify.services.hipchat') && $this->settings->get('notify.hipchat.token') && $this->settings->get('notify.hipchat.room')){
30 | $connectors[] = new HipChatConnector($this->settings);
31 | }
32 | // Check for Gitter
33 | if($this->settings->get('notify.services.gitter') && $this->settings->get('notify.gitter.webhook')){
34 | $connectors[] = new GitterConnector($this->settings);
35 | }
36 | return $connectors;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/dev/src/Api/ConnectorTest.php:
--------------------------------------------------------------------------------
1 | settings = $settings;
23 | $this->bus = $bus;
24 | }
25 |
26 | /**
27 | * Handles the incoming api request and serves it with a Connector test if possible
28 | * @param $request
29 | * @return JsonResponse
30 | */
31 | public function handle($request){
32 | switch($request->input['connector']){
33 | case 'slack':
34 | case 'Slack':
35 | $slackInstance = new SlackConnector($this->settings);
36 | $return = ['success'=> $slackInstance->works()];
37 | break;
38 | case 'hipchat':
39 | case 'HipChat':
40 | $hipChatInstance = new HipChatConnector($this->settings);
41 | $return = ['success'=> $hipChatInstance->works()];
42 | break;
43 | case 'gitter':
44 | case 'Gitter':
45 | $gitterInstance = new GitterConnector($this->settings);
46 | $return = ['success'=> $gitterInstance->works()];
47 | break;
48 | default:
49 | $return = ['success'=>false, 'msg'=>'unknown'];
50 | }
51 | return new JsonResponse($return);
52 | }
53 |
54 | }
--------------------------------------------------------------------------------
/dev/js/admin/src/components/GitterSettingsModal.js:
--------------------------------------------------------------------------------
1 | import Modal from 'flarum/components/Modal';
2 | import Button from 'flarum/components/Button';
3 | import saveConfig from 'flarum/utils/saveConfig';
4 |
5 | export default class GitterSettingsModal extends Modal {
6 | constructor(...args) {
7 | super(...args);
8 |
9 | this.webhook = m.prop(app.config['notify.gitter.webhook'] || '');
10 | }
11 |
12 | className() {
13 | return 'GitterSettingsModal Modal--small';
14 | }
15 |
16 | title() {
17 | return 'Gitter settings';
18 | }
19 |
20 | content() {
21 | return (
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
In order to get your webhook url, visit the room you want to post to on gitter.im. Click on the Settings icon > Integrations > Custom. This will create a new webhook url for you.
To obtain the token, visit your the room settings over at hipchat.com (Login, click on `rooms` and select your the room you want to post to). Click on `Tokens` and create a new one. The label you provide for the token will be shown with each notification.