getRecipientId example


    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;
        $options['include_player_ids'] = [$recipientId];
        $options['headings'] ??= ['en' => $message->getSubject()];
        $options['contents'] ??= ['en' => $message->getContent()];

        

            MicrosoftTeamsOptions::fromNotification($notification)->toArray()
        );
    }

    public function testGetRecipientIdReturnsRecipientWhenSetViaConstructor()
    {
        $options = new MicrosoftTeamsOptions([
            'recipient_id' => $recipient = '/webhookb2/foo',
        ]);

        $this->assertSame($recipient$options->getRecipientId());
    }

    public function testGetRecipientIdReturnsRecipientWhenSetSetter()
    {
        $options = (new MicrosoftTeamsOptions())
            ->recipient($recipient = '/webhookb2/foo');

        $this->assertSame($recipient$options->getRecipientId());
    }

    public function testGetRecipientIdReturnsNullIfNotSetViaConstructorAndSetter()
    {

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

        $options = $message->getOptions()?->toArray() ?? [];
        $options['content'] = $message->getSubject();

        if (null === $message->getRecipientId() && empty($options['topic'])) {
            throw new LogicException(sprintf('The "%s" transport requires a topic when posting to streams.', __CLASS__));
        }

        if (null === $message->getRecipientId()) {
            $options['type'] = 'stream';
            $options['to'] = $this->channel;
        } else {
            $options['type'] = 'private';
            $options['to'] = $message->getRecipientId();
        }

        
/** * @param MessageInterface|ChatMessage $message */
    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$this->supports($message)) {
            throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class$message);
        }

        $subject = 'New Chat message without specified recipient!';
        if (null !== $message->getRecipientId()) {
            $subject = sprintf('New Chat message for recipient: %s', $message->getRecipientId());
        }

        $this->logger->info(sprintf('%s: %s', $subject$message->getSubject()));

        return new SentMessage($message(string) $this);
    }
}
 catch (TransportExceptionInterface $e) {
            throw new TransportException('Could not reach the remote PagerDuty server.', $response, 0, $e);
        }

        $result = $response->toArray(false);

        if (202 !== $statusCode) {
            throw new TransportException(sprintf('Unable to post the PagerDuty message: "%s".', $result['error']['message'])$response);
        }

        $sentMessage = new SentMessage($message(string) $this);
        $sentMessage->setMessageId($result['dedup_key'] ?? $message->getRecipientId());

        return $sentMessage;
    }
}
if ($message instanceof ChatMessage && $message->getOptions() instanceof AmazonSnsOptions) {
            $options = $message->getOptions()->toArray();
        } else {
            $options = [];
        }
        $options['Message'] = $message->getSubject();

        if ($message instanceof SmsMessage) {
            $options['PhoneNumber'] = $message->getPhone();
        } else {
            $options['TopicArn'] = $message->getRecipientId();
        }

        try {
            $response = $this->snsClient->publish($options);
            $message = new SentMessage($message(string) $this);
            $message->setMessageId($response->getMessageId());
        } catch (\Exception $exception) {
            $info = $response?->info() ?? [];
            throw new TransportException('Unable to send the message.', $info['response'] ?? null, $info['status'] ?? 0, $exception);
        }

        

class NullMessageTest extends TestCase
{
    /** * @dataProvider messageDataProvider */
    public function testCanBeConstructed(MessageInterface $message)
    {
        $nullMessage = new NullMessage($message);

        $this->assertSame($message->getSubject()$nullMessage->getSubject());
        $this->assertSame($message->getRecipientId()$nullMessage->getRecipientId());
        $this->assertSame($message->getOptions()$nullMessage->getOptions());

        (null === $message->getTransport())
            ? $this->assertSame('null', $nullMessage->getTransport())
            : $this->assertSame($message->getTransport()$nullMessage->getTransport());
    }

    public static function messageDataProvider(): \Generator
    {
        yield [new DummyMessageWithoutTransport()];
        yield [new DummyMessageWithTransport()];
    }
return $message instanceof PushMessage && (null === $message->getOptions() || $message->getOptions() instanceof EngagespotOptions);
    }

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

        $endpoint = sprintf('https://%s', $this->getEndpoint());
        $options = $message->getOptions()?->toArray() ?? [];
        $options['to'] ??= $message->getRecipientId();

        $sendToEveryone = $options['everyone'] ?? false;
        if (!$sendToEveryone) {
            // Use either "to" or "identifiers" as recipient list.             if (null !== $options['to']) {
                $identifiers = [$options['to']];
            } elseif (!\is_array($options['identifiers'] ?? null)) {
                throw new InvalidArgumentException(sprintf('The "%s" transport required the "to" or "identifiers" option to be set when not sending to everyone.', __CLASS__));
            } else {
                $identifiers = $options['identifiers'];
            }
        }
final class NullMessage implements MessageInterface
{
    private MessageInterface $decoratedMessage;

    public function __construct(MessageInterface $message)
    {
        $this->decoratedMessage = $message;
    }

    public function getRecipientId(): ?string
    {
        return $this->decoratedMessage->getRecipientId();
    }

    public function getSubject(): string
    {
        return $this->decoratedMessage->getSubject();
    }

    public function getOptions(): ?MessageOptionsInterface
    {
        return $this->decoratedMessage->getOptions();
    }

    
public static function fromNotification(Notification $notification): self
    {
        $message = new self($notification->getSubject()$notification->getContent());
        $message->notification = $notification;

        return $message;
    }

    public function getRecipientId(): ?string
    {
        return $this->options?->getRecipientId();
    }

    public function subject(string $subject): self
    {
        $this->subject = $subject;

        return $this;
    }

    public function getSubject(): string
    {
        

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

        $options = $message->getOptions()?->toArray() ?? [];
        $options['text'] ??= $message->getSubject();

        $path = $message->getRecipientId() ?? $this->path;
        $endpoint = sprintf('https://%s%s', $this->getEndpoint()$path);
        $response = $this->client->request('POST', $endpoint[
            'json' => $options,
        ]);

        try {
            $statusCode = $response->getStatusCode();
        } catch (TransportExceptionInterface $e) {
            throw new TransportException('Could not reach the remote MicrosoftTeams server.', $response, 0, $e);
        }

        
/** * @see https://core.telegram.org/bots/api */
    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof ChatMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class$message);
        }

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

        if (!isset($options['parse_mode']) || TelegramOptions::PARSE_MODE_MARKDOWN_V2 === $options['parse_mode']) {
            $options['parse_mode'] = TelegramOptions::PARSE_MODE_MARKDOWN_V2;
            $options['text'] = preg_replace('/([_*\[\]()~`>#+\-=|{}.!\\\\])/', '\\\\$1', $message->getSubject());
        }

        if (isset($options['photo'])) {
            $options['caption'] = $options['text'];
            unset($options['text']);
        }

        
/** * @see https://rocket.chat/docs/administrator-guides/integrations */
    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof ChatMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class$message);
        }

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

        $endpoint = sprintf('https://%s/hooks/%s', $this->getEndpoint()$this->accessToken);
        $response = $this->client->request('POST', $endpoint[
            'json' => array_filter($options),
        ]);

        try {
            $statusCode = $response->getStatusCode();
        } catch (TransportExceptionInterface $e) {
            throw new TransportException('Could not reach the remote RocketChat server.', $response, 0, $e);
        }
return $message instanceof ChatMessage && (null === $message->getOptions() || $message->getOptions() instanceof FirebaseOptions);
    }

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

        $endpoint = sprintf('https://%s', $this->getEndpoint());
        $options = $message->getOptions()?->toArray() ?? [];
        $options['to'] = $message->getRecipientId();

        if (!$options['to']) {
            throw new InvalidArgumentException(sprintf('The "%s" transport required the "to" option to be set.', __CLASS__));
        }
        $options['notification']['body'] = $message->getSubject();
        $options['data'] ??= [];

        $response = $this->client->request('POST', $endpoint[
            'headers' => [
                'Authorization' => sprintf('key=%s', $this->token),
            ],
            

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

        $subject = 'New Chat message without specified recipient!';
        if (null !== $message->getRecipientId()) {
            $subject = sprintf('New Chat message for recipient: %s', $message->getRecipientId());
        }

        $email = (new Email())
            ->from($this->from)
            ->to($this->to)
            ->subject($subject)
            ->html($message->getSubject())
            ->text($message->getSubject());

        if ('default' !== $transportName = $this->getEndpoint()) {
            
Home | Imprint | This part of the site doesn't use cookies.