* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ switch ($modx->event->name) { case 'OnCommentSave': $slackify = $modx->getService('slackify'); /** @var TicketComment $comment */ $comment =& $object; /** @var TicketThread $ticket */ $thread = $comment->getOne('Thread'); /** @var Ticket $ticket */ $ticket = $thread->getOne('Ticket'); $a = new Attachment(); $a->setPretext('Somebody left mention to the important theme on site'); $a->setColor(new Color('#00FF00')); // green $a->setAuthor(new Author($comment->get('name'), 'mailto:' . $comment->get('email'))); $a->setTitle(new Title("left comment to ticket '{$ticket->get('pagetitle')}'")); $a->setText($comment->get('text')); // raw $a->addField(new Field('When', $comment->get('createdon'), true)); $a->addField(new Field('Published', $comment->get('published') ? 'True' : 'False', true)); $a->addField(new Field('Ticket', new Link($modx->makeUrl($ticket->get('id'), 'web', '', 'full'), $ticket->get('pagetitle')))); $message = new Message('*New comment*'); $message->attach($a); $slackify->send($message); break; }
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ switch ($modx->event->name) { case 'OnPageNotFound': $slackify = $modx->getService('slackify'); $a = new Attachment(); $a->setPretext('This is an automated notification of a 404 error that has occured on the site.'); $a->setColor(new Color('#FF0000')); $a->setTitle(new Title($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])); $a->setText('Requested url not found and returns 404 error'); $a->addField(new Field('When', (new DateTime())->format('d M Y - G:i:s'), true)); $a->addField(new Field('Visitor IP', $_SERVER['REMOTE_ADDR'], true)); $a->addField(new Field('User agent', $_SERVER['HTTP_USER_AGENT'])); $message = new Message('*Error 404*, Page not found'); $message->attach($a); $slackify->send($message); break; }
switch ($modx->event->name) { case 'msOnChangeOrderStatus': $slackify = $modx->getService('slackify'); /** @var msOrderStatus $status */ $status = $modx->getObject('msOrderStatus', ['id' => $order->get('status'), 'active' => true]); $new = $order->get('status') == 1; $a = new Attachment(); $a->setPretext($new ? 'New order was made on site' : 'Status of order was changed'); $a->setColor(new Color('#' . $status->get('color'))); // from status /** @var modAction $action */ $action = $modx->getObject('modAction', ['namespace' => 'minishop2', 'controller' => 'controllers/mgr/orders']); $link = new Link(rtrim(MODX_SITE_URL, '/') . MODX_MANAGER_URL . "index.php?a={$action->get('id')}#&order={$order->get('id')}", $order->get('num')); $title = $new ? "New order {$link} was placed on the site" : "Order {$link} was updated"; $a->setTitle(new Title($title)); $a->addField(new Field('Status', $status->get('name'), true)); $a->addField(new Field('When', $order->get('createdon'), true)); if ($new) { $a->addField(new Field('Cost', $order->get('cost'), true)); $a->addField(new Field('Cart cost', $order->get('cost'), true)); $a->addField(new Field('Delivery', $order->getOne('Delivery')->get('name'), true)); $a->addField(new Field('Delivery cost', $order->get('delivery_cost'), true)); $a->addField(new Field('Payment', $order->getOne('Payment')->get('name'), true)); $a->addField(new Field('Weight'), $order->get('weight')); $a->setText($order->get('comment')); } $message = new Message($new ? '*New order*' : '*Order status update*'); $message->attach($a); $slackify->send($message); break; }
* SOFTWARE. */ switch ($modx->event->name) { case 'OnDocFormSave': if ($resource->get('class_key') !== 'Ticket') { return; } if (!empty($mode) && $mode != 'new') { return; } $slackify = $modx->getService('slackify'); /** @var Ticket $ticket */ $ticket =& $resource; /** @var modUser $creator */ $creator = $ticket->getOne('CreatedBy'); /** @var modUserProfile $profile */ $creatorProfile = $creator->getOne('Profile'); $a = new Attachment(); $a->setPretext('Somebody add new important theme for discussion to the site'); $a->setColor(new Color('#0000FF')); // blue $a->setAuthor(new Author($creatorProfile->get('fullname'), 'mailto:' . $creatorProfile->get('email'))); $ticketTitle = new Link($modx->makeUrl($ticket->get('id'), 'web', '', 'full'), $ticket->get('pagetitle')); $a->setTitle(new Title("add new ticket '{$ticketTitle}'")); $a->setText($ticket->get('introtext')); $a->addField(new Field('When', $ticket->get('createdon'), true)); $message = new Message('*New ticket*'); $message->attach($a); $slackify->send($message); break; }