namespace App\Console\Commands;
use App\Console\Commands\Base\ToolboxCommand;
+use App\Slack\Mattermost;
use App\Slack\Slack;
use Cubist\Backpack\Facades\App;
App::setLocale('fr');
$nottreated = \App\Models\FluidbookQuote::where('status', '0')->count();
if ($nottreated > 0) {
- Slack::send(Slack::fluidbookQuoteChannel,
+ Mattermost::send(Mattermost::fluidbookQuoteChannel,
':alarm_clock: ' . __('Des demandes de devis n\'ont pas été traitées'),
__(':awaiting demandes de devis doivent être confiées à un revendeur ou un chef de projet', ['awaiting' => $nottreated]),
[__('Toutes les demandes') => ['url' => backpack_url('fluidbook-quote?status=0')]],
--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\Commands\Base\ToolboxCommand;
+use App\Models\Quiz;
+use App\Models\User;
+use App\Slack\Mattermost;
+
+class MattermostPost extends ToolboxCommand
+{
+ protected $signature = 'mattermost:post';
+
+ public function handle()
+ {
+ $id = User::withoutGlobalScopes()->find(5)->mattermost;
+ Mattermost::send($id, 'Test subject', 'Test Text', ['test' => ['url' => 'https://example.com']]);
+ }
+}
{
public function ignore()
{
- if (!static::_getURL($this->to,'intex', false)) {
+ if (!static::_getURL($this->to, 'intex', false)) {
return true;
}
return parent::ignore();
}
- public static function _getURL($to)
+ public static function _getURL($to, $type = '', $default = null)
{
- return static::_getURL( $to,'intex');
+ return static::_getURL($to, 'intex');
}
public function getDefaultTooltip()
class PierronLink extends CustomLink
{
- public static function _getURL($to)
+ public static function _getURL($to,$type='',$default=null)
{
return 'https://workshop.fluidbook.com/services/pierronRef?ref=' . $to;
}
use App\Models\File;
use App\Models\User;
+use App\Slack\Mattermost;
use App\Slack\Slack;
use Cubist\Util\Files\Files;
use Illuminate\Http\UploadedFile;
/** @var User $destUser */
$destUser = User::withoutGlobalScopes()->find($user);
$subject = __(':nb fichiers chargés pour ' . $destUser->nameWithCompany, ['nb' => $j]);
- $destChannel = backpack_user()->slack;
+ $destChannel = backpack_user()->mattermost;
} else {
$subject = __(':nb fichiers chargés par ' . backpack_user()->nameWithCompany, ['nb' => $j]);
- $destChannel = Slack::fluidbookFilesChannel;
+ $destChannel = Mattermost::fluidbookFilesChannel;
}
$actions = [];
foreach ($paths as $path) {
$spl = new \SplFileInfo($path);
$actions[$spl->getFilename()] = backpack_url('/file/' . File::hash($path, $spl->getSize()) . '/' . $spl->getFilename());
}
- Slack::send($destChannel, $subject, '', $actions);
+ Mattermost::send($destChannel, $subject, '', $actions);
Alert::success(__(':nb fichiers chargés', ['nb' => '<b>' . $j . '</b>']))->flash();
}
return redirect($this->crud->route);
use App\Models\Company;
use App\Models\FluidbookQuote;
use App\Models\AuthUser;
+use App\Slack\Mattermost;
use App\Slack\Slack;
use Cubist\Backpack\Middleware\CORSMiddleware;
use Cubist\Util\ArrayUtil;
if ($post && !$spam) {
try {
- $quote->slack_ts = Slack::send(Slack::fluidbookQuoteChannel, 'Demande de devis', FluidbookQuoteReceived::getMarkdown($post),
+ $quote->slack_ts = Mattermost::send(Mattermost::fluidbookQuoteChannel, 'Demande de devis', FluidbookQuoteReceived::getMarkdown($post),
['Je vais voir' => backpack_url('fluidbook-quote', ['status' => 0]),
'Je m\'en charge' => ['url' => backpack_url('fluidbook-quote/' . $quote->id . '/assign/me'), 'style' => 'primary'],
'C\'est du SPAM' => ['url' => backpack_url('fluidbook-quote/' . $quote->id . '/spam'), 'style' => 'danger'],
$data = unserialize($d64);
}
if (!$data) {
- Slack::send(Slack::fluidbookQuoteChannel, __('Erreur envoi demande de devis'), $request->get('data') . "\n\n" . utf8_decode($d64));
+ Mattermost::send(Mattermost::fluidbookQuoteChannel, __('Erreur envoi demande de devis'), $request->get('data') . "\n\n" . utf8_decode($d64));
return false;
}
use App\Models\User;
use App\Notifications\DownloadReady;
use App\Services\ScormCloud;
+use App\Slack\Mattermost;
use App\Slack\Slack;
use Cubist\Backpack\Facades\App;
use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
public function sendSlack($subject, $text, $actions = [])
{
- return Slack::send($this->getUser()->slack, $subject, $text, $actions);
+ return Mattermost::send($this->getUser()->mattermost, $subject, $text, $actions);
}
/**
use App\Models\ToolWebflow;
use App\Models\User;
use App\Notifications\ToolboxNotification;
+use App\Slack\Mattermost;
use App\Slack\Slack;
class WebflowPublish extends Base
}
if ($notify && isset($text)) {
if ($this->user === null) {
- Slack::send($wf->slack, $subject, $text, $actions, false);
+ Mattermost::send($wf->mattermost, $subject, $text, $actions, false);
} else {
$this->user->notify(new ToolboxNotification($subject, $text, $actions, true));
}
use App\Jobs\RefreshUsersTree;
use App\Models\Base\ToolboxStatusModel;
use App\Models\Traits\CheckHash;
+use App\Slack\Mattermost;
use App\Slack\Slack;
use App\SubForms\CollectionPublication;
use Cubist\Backpack\Magic\Fields\BunchOfFieldsMultiple;
$owner = \App\Models\User::withoutGlobalScopes()->find($this->owner);
$actions = [];
- Slack::send(Slack::fluidbookPreviewAlertsChannel,
+ Mattermost::send(Mattermost::fluidbookPreviewAlertsChannel,
'Collection #' . $this->id . ' : ' . $this->visits_counter . ' visites',
'Le lien de preview de _' . $this->title . '_ a été utilisé à *' . $this->visits_counter . '* reprises par des visiteurs non authentifiés sur la toolbox. La collection se trouve sur le compte de ' . $owner->getNameWithCompanyAttribute() . '.',
$actions,
$actions['Voir les stats'] = backpack_url('/fluidbook-publication/stats/' . $this->id . '_' . $this->hash . '/');
}
- Slack::send(Slack::fluidbookPreviewAlertsChannel,
+ Mattermost::send(Mattermost::fluidbookPreviewAlertsChannel,
'Fluidbook #' . $this->id . ' : ' . $this->visits_counter . ' visites',
'Le lien de preview de _' . $this->title . '_ a été utilisé à *' . $this->visits_counter . '* reprises par des visiteurs non authentifiés sur la toolbox. Le fluidbook se trouve sur le compte de ' . $owner->getNameWithCompanyAttribute() . '.',
$actions,
--- /dev/null
+<?php
+
+namespace App\Notifications;
+
+use App\Slack\Mattermost;
+use Illuminate\Notifications\Notification;
+
+class FluidbookmattermostChannel
+{
+ /**
+ * Send the given notification.
+ *
+ * @param mixed $notifiable
+ * @param \Illuminate\Notifications\Notification $notification
+ * @return void
+ */
+ public function send($notifiable, Notification $notification)
+ {
+ $message = $notification->toSlack($notifiable);
+ Mattermost::send($notifiable->mattermost, $message['subject'], $message['text'], $message['actions']);
+ }
+}
*/
public function via($notifiable)
{
+ $res = ['database'];
+ $slackOrMM=false;
if ($notifiable->slack) {
- if ($notifiable->id == 5) {
- return ['database', FluidbookslackChannel::class, 'mail', WebPushChannel::class];
- }
- return ['database', FluidbookslackChannel::class];
+ $res[] = FluidbookslackChannel::class;
+ $slackOrMM=true;
}
- return ['database', 'mail', WebPushChannel::class];
+ if ($notifiable->mattermost) {
+ $res[] = FluidbookmattermostChannel::class;
+ $slackOrMM=true;
+ }
+
+ if(!$slackOrMM || $notifiable->id === 5){
+ $res[] = 'mail';
+ }
+
+ return array_unique($res);
}
/**
--- /dev/null
+<?php
+
+namespace App\Slack;
+
+use Illuminate\Support\Facades\Log;
+use Pnz\MattermostClient\ApiClient;
+use Pnz\MattermostClient\HttpClientConfigurator;
+
+class Mattermost
+{
+ /**
+ * @var null|ApiClient
+ */
+ protected static $_client = null;
+
+ const fluidbookQuoteChannel = 'tswc7buu1bf9ixdccfqmo36s5r';
+ const fluidbookPreviewAlertsChannel = 'y1z7rdtppbg1jr91o8f6prcbcc';
+ const fluidbookFilesChannel='6sgtn7rrw3buz8fqftm936oqer';
+
+
+ protected static function _client(): ApiClient
+ {
+ if (null === self::$_client) {
+
+ $endpoint = 'https://mm.cubedesigners.com/api/v4';
+ $username = 'vincent+toolbox@cubedesigners.com';
+ $password = 'HtMYveJ3%8HMnWooXsm9';
+
+ $configurator = (new HttpClientConfigurator())
+ ->setEndpoint($endpoint)
+ ->setCredentials($username, $password);
+ self::$_client = ApiClient::configure($configurator);
+ }
+ return self::$_client;
+ }
+
+ public static function send($channel, $subject, $text, $actions = [], $repeatActions = true, $from = 'Fluidbook Toolbox')
+ {
+ Log::debug(json_encode(func_get_args()));
+ $markdown = '';
+ if ($text) {
+ $markdown .= $text . "\n";
+ }
+
+ $attachment = ['title' => $subject, 'color' => '#9fc142'];
+ $a = [];
+ $actionsTexts = [];
+ $actionsCount = count($actions);
+ $repeatActions = true;
+ if ($actionsCount > 0) {
+ $i = 0;
+ foreach ($actions as $label => $data) {
+ if (!$data) {
+ $data = ['url' => ''];
+ }
+ if (is_string($data)) {
+ $data = ['url' => $data];
+ }
+ if (!$data['url']) {
+ $data['url'] = backpack_url('404');
+ }
+// if ($i < 6) {
+// $aa = ['id' => 'a_' . $i, 'name' => $label, 'type' => 'link', 'style' => 'error', 'integration' => ['url' => $data['url']]];
+// $a[] = $aa;
+// }
+ if ($repeatActions) {
+ $markdown .= '* ' . $label . ' : ' . $data['url'] . "\n";
+ }
+ $i++;
+ }
+ $attachment['actions'] = $a;
+
+ }
+ $attachment['text'] = $markdown;
+ $props['attachments'] = [$attachment];
+
+ try {
+
+ $response = self::_client()->posts()->createPost([
+ 'channel_id' => $channel,
+ 'props' => $props,
+ ]);
+ } catch (\Exception $e) {
+ Log::critical($e);
+ Log::critical($e->getMessage() . ' // ' . $from . ' // ' . $channel . ' // ' . $text . ' // ' . $markdown);
+ }
+ return false;
+ }
+
+ public static function deleteMessage($postId)
+ {
+ return self::_client()->posts()->deletePost($postId)->getStatus();
+ }
+
+ public static function addReaction($channel, $ts, $reaction)
+ {
+ return self::_client()->reactionsAdd(['channel' => $channel, 'timestamp' => $ts, 'name' => $reaction]);
+ }
+}