/', "\n", $html); // $html = preg_replace('#<\/?(p|div|span|h[1-6])[^>]*>#i', '', $html); // $this->logger->info('Final - ' . $html); // return trim($html); // } // public function openConversationWithInstaller(string $installerSlackId, string $botToken): ?string // { // $response = $this->httpClient->request('POST', 'https://slack.com/api/conversations.open', [ // 'headers' => [ // 'Authorization' => 'Bearer ' . $botToken, // 'Content-Type' => 'application/json', // ], // 'json' => [ // 'users' => $installerSlackId, // ], // ]); // $data = $response->toArray(); // return (!empty($data['ok']) && isset($data['channel']['id'])) ? $data['channel']['id'] : null; // } // public function sendSlackHomeView(string $userId, array $buttons, string $botToken, array $brandBlocks = []): void // { // $blocks = [ // [ // 'type' => 'header', // 'text' => [ // 'type' => 'plain_text', // 'text' => "Des prix doux toute l’année 😎", // ], // ], // [ // 'type' => 'section', // 'text' => [ // 'type' => 'mrkdwn', // 'text' => "Réductions négociées, accès sans mot de passe.\nVous cliquez, vous profitez. Merci Korak ✌️", // ], // ], // [ // 'type' => 'section', // 'text' => [ // 'type' => 'mrkdwn', // 'text' => "Choisissez une catégorie :", // ], // ], // [ // 'type' => 'actions', // 'elements' => $buttons, // ], // ]; // if (!empty($brandBlocks)) { // foreach ($brandBlocks as $block) { // $blocks[] = $block; // } // } // $this->httpClient->request('POST', 'https://slack.com/api/views.publish', [ // 'headers' => [ // 'Authorization' => 'Bearer ' . $botToken, // 'Content-Type' => 'application/json', // ], // 'json' => [ // 'user_id' => $userId, // 'view' => [ // 'type' => 'home', // 'blocks' => $blocks, // ], // ], // ]); // } // public function getAvailableCategoriesForCse(Cse $cse): array // { // $categories = []; // $cseChannels = $this->entityManager->getRepository(CseChannels::class) // ->findBy(['cse' => $cse]); // foreach ($cseChannels as $cseChannel) { // $channel = $cseChannel->getChannel(); // if ($channel) { // foreach ($channel->getCategories() as $category) { // $categories['category_' . $category->getId()] = $category; // } // } // } // $virtualAllCategory = (object)[ // 'id' => 'all', // 'title' => 'Toutes nos marques', // 'emoji' => '✨', // ]; // $categories['category_all'] = $virtualAllCategory; // return $categories; // } // public function buildSlackCategoryButtons(array $categories, ?string $selected = null): array // { // usort($categories, function ($a, $b) { // $aTitle = $a instanceof ChannelCategory ? $a->getTitle() : ($a->title ?? ''); // $bTitle = $b instanceof ChannelCategory ? $b->getTitle() : ($b->title ?? ''); // if ($aTitle === 'Toutes nos marques') return -1; // if ($bTitle === 'Toutes nos marques') return 1; // $aId = $a instanceof ChannelCategory ? $a->getId() : ($a->id ?? 0); // $bId = $b instanceof ChannelCategory ? $b->getId() : ($b->id ?? 0); // return $aId <=> $bId; // }); // $buttons = []; // foreach ($categories as $category) { // $id = method_exists($category, 'getId') ? $category->getId() : ($category->id ?? null); // $title = method_exists($category, 'getTitle') ? $category->getTitle() : ($category->title ?? ''); // $emoji = method_exists($category, 'getEmoji') ? $category->getEmoji() : ($category->emoji ?? ''); // $actionId = $id === 'all' ? 'category_all' : 'category_' . $id; // $label = trim(($emoji ?? '') . ' ' . $title); // $button = [ // 'type' => 'button', // 'text' => [ // 'type' => 'plain_text', // 'text' => $label, // 'emoji' => true, // ], // 'action_id' => $actionId, // ]; // if ($selected === $actionId) { // $button['style'] = 'primary'; // } // $buttons[] = $button; // } // return $buttons; // } // public function buildSlackBrandBlocks(array $brands, Cse $cse): array // { // try { // $lines = array_filter(array_map(function ($brand) use ($cse) { // $channel = $this->channelRepository->findOneBy(['name' => $brand['name']]); // $cseChannel = $this->entityManager->getRepository(CseChannels::class)->findOneBy(['cse' => $cse, 'channel' => $channel]); // $url = $cseChannel?->getInvitationUrl(); // if (!$url) { // $this->logger->error("Pas de lien d’invitation pour {$brand['name']}"); // return null; // } // $isEmployeeChannel = $channel && $channel->getSlackCse()?->getId() === $cse->getId(); // $link = $isEmployeeChannel // ? "<{$url}|*{$brand['name']}*>" // : "<{$url}|{$brand['name']}>"; // $extras = []; // if (!empty($brand['description'])) { // $extras[] = $isEmployeeChannel ? "*{$brand['description']}*" : $brand['description']; // } // if (!empty($brand['discount'])) { // $extras[] = $isEmployeeChannel ? "*{$brand['discount']}*" : $brand['discount']; // } // $line = "• {$link}"; // if (!empty($extras)) { // $line .= ' : ' . implode(' - ', $extras); // } // return $line; // }, $brands)); // if (empty($lines)) { // return [[ // 'type' => 'section', // 'text' => [ // 'type' => 'mrkdwn', // 'text' => "_Aucune marque n'est encore activée pour votre Slack._", // ], // ]]; // } // // Cut the lines into chunks to fit Slack's block size limit // $chunks = []; // $currentBlock = "*Vos avantages marques disponibles :*"; // foreach ($lines as $line) { // if (strlen($currentBlock . "\n" . $line) > 2900) { // $chunks[] = $currentBlock; // $currentBlock = $line; // } else { // $currentBlock .= "\n" . $line; // } // } // $chunks[] = $currentBlock; // //turn chunks into Slack blocks // return array_map(fn($chunk) => [ // 'type' => 'section', // 'text' => [ // 'type' => 'mrkdwn', // 'text' => $chunk, // ], // ], $chunks); // } catch (\Throwable $e) { // $this->logger->error('Error building Slack brand block: ' . $e->getMessage()); // return []; // } // } // }
Content de vous revoir 😃