getNotification example


    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof ChatMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class$message);
        }

        if (($options = $message->getOptions()) && !$options instanceof LinkedInOptions) {
            throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, LinkedInOptions::class));
        }

        if (!$options && $notification = $message->getNotification()) {
            $options = LinkedInOptions::fromNotification($notification);
            $options->author(new AuthorShare($this->accountId));
        }

        $endpoint = sprintf('https://%s/v2/ugcPosts', $this->getEndpoint());

        $response = $this->client->request('POST', $endpoint[
            'auth_bearer' => $this->authToken,
            'headers' => ['X-Restli-Protocol-Version' => '2.0.0'],
            'json' => array_filter($options?->toArray() ?? $this->bodyFromMessageWithNoOption($message)),
        ]);

        


    /** * @see https://api.slack.com/methods/chat.postMessage */
    protected function doSend(MessageInterface $message): SlackSentMessage
    {
        if (!$message instanceof ChatMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class$message);
        }

        if (!($options = $message->getOptions()) && $notification = $message->getNotification()) {
            $options = SlackOptions::fromNotification($notification);
        }

        $options = $options?->toArray() ?? [];
        $options['channel'] ??= $message->getRecipientId() ?: $this->chatChannel;
        $options['text'] = $message->getSubject();

        $apiMethod = $message->getOptions() instanceof UpdateMessageSlackOptions ? 'chat.update' : 'chat.postMessage';
        $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/api/'.$apiMethod[
            'json' => array_filter($options),
            'auth_bearer' => $this->accessToken,
            


    /** * @see https://documentation.onesignal.com/reference/create-notification */
    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof PushMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, PushMessage::class$message);
        }

        if (!($options = $message->getOptions()) && $notification = $message->getNotification()) {
            $options = OneSignalOptions::fromNotification($notification);
        }

        $recipientId = $message->getRecipientId() ?? $this->defaultRecipientId;

        if (null === $recipientId) {
            throw new LogicException(sprintf('The "%s" transport should have configured `defaultRecipientId` via DSN or provided with message options.', __CLASS__));
        }

        $options = $options?->toArray() ?? [];
        $options['app_id'] = $this->appId;
        

        if (!$message instanceof ChatMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class$message);
        }

        $endpoint = sprintf('https://%s/api/v2/tickets.json', $this->getEndpoint());

        $body = [
            'ticket' => [
                'subject' => $message->getSubject(),
                'comment' => [
                    'body' => $message->getNotification()?->getContent() ?? '',
                ],
            ],
        ];

        $options = $message->getOptions()?->toArray() ?? [];
        if (isset($options['priority'])) {
            $body['ticket']['priority'] = $options['priority'];
        }

        $response = $this->client->request('POST', $endpoint[
            'auth_basic' => [$this->email.'/token', $this->token],
            
protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof PushMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, PushMessage::class$message);
        }

        if ($message->getOptions() && !$message->getOptions() instanceof NtfyOptions) {
            throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, NtfyOptions::class));
        }

        if (!($opts = $message->getOptions()) && $notification = $message->getNotification()) {
            $opts = NtfyOptions::fromNotification($notification);
        }

        $options = $opts ? $opts->toArray() : [];

        $options['topic'] = $this->getTopic();

        if (!isset($options['title'])) {
            $options['title'] = $message->getSubject();
        }
        if (!isset($options['message'])) {
            
protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof ChatMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class$message);
        }

        if (($options = $message->getOptions()) && !$options instanceof GoogleChatOptions) {
            throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, GoogleChatOptions::class));
        }

        if (!$options) {
            if ($notification = $message->getNotification()) {
                $options = GoogleChatOptions::fromNotification($notification);
            } else {
                $options = GoogleChatOptions::fromMessage($message);
            }
        }

        $threadKey = $options->getThreadKey() ?: $this->threadKey;

        $url = sprintf('https://%s/v1/spaces/%s/messages?key=%s&token=%s%s',
            $this->getEndpoint(),
            $this->space,
            


    public function testCreateFromNotification()
    {
        $notification = new Notification('Hello');
        $notification->content('World');

        $message = PushMessage::fromNotification($notification);

        $this->assertSame('Hello', $message->getSubject());
        $this->assertSame('World', $message->getContent());
        $this->assertSame($notification$message->getNotification());
    }
}
Home | Imprint | This part of the site doesn't use cookies.