public function notify(DojoCreatedEvent $event) { $attachment = new Attachment(); $attachment->setFallback(sprintf('Er is een nieuwe dojo toegevoegd! %s (Website: $s)', $event->getName(), $event->getWebsite())); $attachment->setText('Er is een nieuwe dojo toegevoegd, welkom! Is dit jouw dojo? Claim hem op coderdojo.nl'); $attachment->setColor('good'); $nameField = new AttachmentField(); $nameField->setTitle('Name'); $nameField->setValue($event->getName()); $nameField->setShort(true); $cityField = new AttachmentField(); $cityField->setTitle('City'); $cityField->setValue($event->getCity()); $cityField->setShort(true); $emailField = new AttachmentField(); $emailField->setTitle('Email:'); $emailField->setValue($event->getEmail()); $emailField->setShort(true); $websiteField = new AttachmentField(); $websiteField->setTitle('Website'); $websiteField->setValue($event->getWebsite()); $websiteField->setShort(true); $attachment->addField($nameField); $attachment->addField($cityField); $attachment->addField($emailField); $attachment->addField($websiteField); $this->slackService->sendToChannel('#website-nl', '', [$attachment]); }
/** * {@inheritdoc} */ protected function createPayload() { $payload = new ChatPostMessagePayload(); $payload->setChannel('#acme_channel'); $payload->setUsername('acme_user'); $payload->setText('Hello World!'); $payload->setIconEmoji(':truck:'); $payload->setLinkNames(true); $payload->setParse('full'); $payload->setUnfurlLinks(true); $payload->setUnfurlMedia(false); $payload->setIconUrl('http://foo.bar/emoji-1.png'); $fakeAttachmentField = new AttachmentField(); $fakeAttachmentField->setShort(false); $fakeAttachmentField->setTitle('the title'); $fakeAttachmentField->setValue('the value'); $fakeAttachment = new Attachment(); $fakeAttachment->setTitle('the title'); $fakeAttachment->setTitleLink('http://thetitlelink.com'); $fakeAttachment->setColor('the color'); $fakeAttachment->setFallback('the fallback'); $fakeAttachment->setImageUrl('the image url'); $fakeAttachment->setPreText('this is...'); $fakeAttachment->setText('my attachment'); $fakeAttachment->setAuthorIcon(':skull:'); $fakeAttachment->setAuthorName('the author'); $fakeAttachment->setAuthorLink('http://theauthor.com'); $fakeAttachment->addField($fakeAttachmentField); $payload->addAttachment($fakeAttachment); return $payload; }
protected function notifySlack($message, $project, $env, $user, $resolverArray, $color = "#FFCC00", $update = false) { if ($update) { $payload = new ChatDeletePayload(); $payload->setSlackTimestamp($this->ts); $payload->setChannelId($this->channel); $response = $this->slackApiClient->send($payload); if ($response->isOk()) { if ($response instanceof ChatPostMessagePayloadResponse) { /** @var ChatPostMessagePayloadResponse $response */ $this->ts = $response->getSlackTimestamp(); } } else { // something went wrong, but what? // simple error (Slack's error message) echo $response->getError(); // explained error (Slack's explanation of the error, according to the documentation) echo $response->getErrorExplanation(); exit(1); } } $payload = new ChatPostMessagePayload(); $payload->setChannel("#" . getenv("slack_channel")); $payload->setIconUrl("https://www.dropbox.com/s/ivrj3wcze7cwh54/masterjenkins.png?dl=1"); $payload->setUsername("Master Jenkins"); $attachment = new Attachment(); $attachment->setColor($color); $attachment->setFallback("[" . $project . "#" . getenv("BUILD_NUMBER") . " - branch *" . getenv("GIT_BRANCH") . "* to *" . $env . "* by _" . $user . "_] " . $message); $attachment->setText("[" . $project . "#" . getenv("BUILD_NUMBER") . " - branch *" . getenv("GIT_BRANCH") . "* to *" . $env . "* by _" . $user . "_] " . $message . "\n<" . getenv("BUILD_URL") . "console|Jenkins Console> - <" . getenv("BUILD_URL") . "changes|Changes>" . (isset($resolverArray["shared_package_target"]) && file_exists($resolverArray["shared_package_target"]) ? " - <" . $resolverArray["shared_package_url"] . "|Download>" : "")); $payload->addAttachment($attachment); $response = $this->slackApiClient->send($payload); if ($response->isOk()) { if ($response instanceof ChatPostMessagePayloadResponse) { /** @var ChatPostMessagePayloadResponse $response */ $this->ts = $response->getSlackTimestamp(); $this->channel = $response->getChannelId(); } } else { // something went wrong, but what? // simple error (Slack's error message) echo $response->getError(); // explained error (Slack's explanation of the error, according to the documentation) echo $response->getErrorExplanation(); exit(1); } }
public function run(OutputInterface $output) { $output->writeln('**********************************'); $output->writeln('Starting sync for Events'); $progressbar = $this->newProgressBar($output); $zenIds = $this->doctrine->getRepository('CoderDojoWebsiteBundle:Dojo')->getZenIds(); $externalEvents = $this->zen->getEvents($zenIds); $progressbar->start(count($externalEvents)); $progressbar->setMessage('Iterating Events...'); $countNew = 0; $countUpdated = 0; $countNoMatch = 0; foreach ($externalEvents as $externalEvent) { $progressbar->setMessage('Handling ' . $externalEvent->getName()); $internalEvent = $this->doctrine->getRepository('CoderDojoWebsiteBundle:DojoEvent')->findOneBy(['zenId' => $externalEvent->getZenId()]); /** @var Dojo $dojo */ $internalDojo = $this->doctrine->getRepository('CoderDojoWebsiteBundle:Dojo')->findOneBy(['zenId' => $externalEvent->getZenDojoId()]); if (null === $internalDojo) { $progressbar->setMessage('No internal dojo found!'); $progressbar->advance(); $countNoMatch++; continue; } if (null === $internalEvent) { $progressbar->setMessage('No internal event found'); $command = new CreateEventCommand($internalDojo->getId(), $externalEvent->getName(), $externalEvent->getStartTime(), $internalDojo->getZenUrl(), $externalEvent->getZenId(), DojoEvent::TYPE_ZEN); $this->commandBus->handle($command); $progressbar->advance(); $countNew++; } else { $progressbar->setMessage('Internal event found'); $internalEvent->setName($externalEvent->getName()); $internalEvent->setDate($externalEvent->getStartTime()); $internalEvent->setUrl($internalDojo->getZenUrl()); $progressbar->advance(); $countUpdated++; } } $progressbar->setMessage('Flushing'); $this->doctrine->flush(); $progressbar->setMessage('Finished syncing Events!'); $progressbar->finish(); $output->writeln($countNew . ' New events added'); $output->writeln($countUpdated . ' Existing events updated'); $output->writeln($countNoMatch . ' events could not be matched with a dojo'); $message = "Zen synchronizer just handled events."; $attachments = []; $attachment = new Attachment(); $attachment->setFallback($countNew . " events added."); $attachment->setText($countNew . " events added."); $attachment->setColor('good'); $attachments[] = $attachment; $attachment = new Attachment(); $attachment->setFallback($countUpdated . " events updated."); $attachment->setText($countUpdated . " events updated."); $attachment->setColor('warning'); $attachments[] = $attachment; $attachment = new Attachment(); $attachment->setFallback($countNoMatch . " events not matched."); $attachment->setText($countNoMatch . " events not matched."); $attachment->setColor('danger'); $attachments[] = $attachment; $this->slackService->sendToChannel('#website-nl', $message, $attachments); }
/** * Created notification for slack to keep us up to date on the sync process */ private function notifySlack() { $message = "Zen synchronizer just handled dojo's."; $attachments = []; $attachment = new Attachment(); $attachment->setFallback($this->countNew . " dojo's added."); $attachment->setText($this->countNew . " dojo's added."); $attachment->setColor('good'); $attachments[] = $attachment; $attachment = new Attachment(); $attachment->setFallback($this->countUpdated . " dojo's updated."); $attachment->setText($this->countUpdated . " dojo's updated."); $attachment->setColor('warning'); $attachments[] = $attachment; $attachment = new Attachment(); $attachment->setFallback($this->countRemoved . " dojo's removed."); $attachment->setText($this->countRemoved . " dojo's removed."); $attachment->setColor('danger'); $attachments[] = $attachment; $this->slackService->sendToChannel('#website-nl', $message, $attachments); foreach ($this->unmatched as $unmatched) { $attachment = new Attachment(); $attachment->setFallback(sprintf('This dojo resulted in multiple internal possibilities: %s (zen: $s)', $unmatched->getName(), $unmatched->getZenId())); $attachment->setText('A dojo resulted in multiple internal possibilities'); $attachment->setColor('danger'); $nameField = new AttachmentField(); $nameField->setTitle('Name'); $nameField->setValue($unmatched->getName()); $nameField->setShort(true); $cityField = new AttachmentField(); $cityField->setTitle('City'); $cityField->setValue($unmatched->getCity()); $cityField->setShort(true); $zenIdField = new AttachmentField(); $zenIdField->setTitle('Zen ID'); $zenIdField->setValue($unmatched->getZenId()); $zenIdField->setShort(true); $zenUrlField = new AttachmentField(); $zenUrlField->setTitle('Zen Url'); $zenUrlField->setValue($unmatched->getZenUrl()); $zenUrlField->setShort(true); $attachment->addField($nameField); $attachment->addField($cityField); $attachment->addField($zenIdField); $attachment->addField($zenUrlField); $this->slackService->sendToChannel('#website-nl', 'We couldn\'t match this dojo internally.', [$attachment]); } }