SentMessage example

'json' => array_filter($options),
        ]);

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

        if (200 === $statusCode) {
            $result = $response->toArray();
            $sentMessage = new SentMessage($message(string) $this);

            $messageId = $result['batch']['messageheaders'][0]['id'] ?? null;
            if ($messageId) {
                $sentMessage->setMessageId($messageId);
            }

            return $sentMessage;
        }

        $message = sprintf('Unable to send the SMS: error %d.', $statusCode);

        
if (200 !== $statusCode) {
            $requestUniqueIdentifier = $content['meta']['uniqId'] ?? '';

            $errorMessage = $content['errors'][0]['message'] ?? '';

            throw new TransportException(sprintf('Unable to send the SMS: '.$errorMessage.'. UniqId: (%s).', $requestUniqueIdentifier)$response);
        }

        $messageId = $content['data'][0]['externalId'] ?? '';

        $sentMessage = new SentMessage($message(string) $this);

        $sentMessage->setMessageId($messageId);

        return $sentMessage;
    }
}
if (201 !== $statusCode) {
            $result = $response->toArray(false);

            $errorMessage = $result['error'];
            if (\is_array($errorMessage)) {
                $errorMessage = implode(' | ', array_values($errorMessage));
            }

            throw new TransportException(sprintf('Unable to post the Zendesk message: "%s".', $errorMessage)$response);
        }

        return new SentMessage($message(string) $this);
    }
}
$error = $response->toArray(false);

            throw new TransportException(sprintf('Unable to send the SMS: %s.', $error['message'])$response);
        }

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

        if (!isset($success['ids'][0])) {
            throw new TransportException(sprintf('Attempt to send the SMS to invalid receivers: "%s".', implode(',', $success['invalidReceivers']))$response);
        }

        $sentMessage = new SentMessage($message(string) $this);
        $sentMessage->setMessageId($success['ids'][0]);

        return $sentMessage;
    }

    /** * Calculates the time delta between the local machine and the API server. */
    private function calculateTimeDelta(): int
    {
        $endpoint = sprintf('https://%s/1.0/auth/time', $this->getEndpoint());
        
/** * @dataProvider messagesProvider */
    public function testGetMessage(SentMessage $message, SentMessageEvent $event)
    {
        $this->assertSame($message$event->getMessage());
    }

    public static function messagesProvider(): iterable
    {
        yield [$message = new SentMessage(new ChatMessage('subject'), 'null_transport')new SentMessageEvent($message)];
        yield [$message = new SentMessage(new SmsMessage('+3312345678', 'subject'), 'null_transport')new SentMessageEvent($message)];
    }
}
throw new TransportException('Could not reach the remote Vonage server.', $response, 0, $e);
        }

        foreach ($result['messages'] as $msg) {
            if ($msg['status'] ?? false) {
                throw new TransportException('Unable to send the SMS: '.$msg['error-text'].sprintf(' (code %s).', $msg['status'])$response);
            }
        }

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

        $sentMessage = new SentMessage($message(string) $this);
        $sentMessage->setMessageId($success['messages'][0]['message-id']);

        return $sentMessage;
    }
}
if (201 !== $statusCode) {
            throw new TransportException(sprintf('Unable to post the Linkedin message: "%s".', $response->getContent(false))$response);
        }

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

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

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

        return $sentMessage;
    }

    private function bodyFromMessageWithNoOption(MessageInterface $message): array
    {
        return [
            'specificContent' => [
                'com.linkedin.ugc.ShareContent' => [
                    'shareCommentary' => [
                        
throw new TransportException('Could not reach the remote Sinch server.', $response, 0, $e);
        }

        if (201 !== $statusCode) {
            $error = $response->toArray(false);

            throw new TransportException(sprintf('Unable to send the SMS: %s (%s).', $error['text']$error['code'])$response);
        }

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

        $sentMessage = new SentMessage($message(string) $this);
        $sentMessage->setMessageId($success['id']);

        return $sentMessage;
    }
}
 catch (TransportExceptionInterface $e) {
            throw new TransportException('Could not reach the remote SpotHit server.', $response, 0, $e);
        } catch (HttpExceptionInterface|DecodingExceptionInterface $e) {
            throw new TransportException('Unexpected reply from the remote SpotHit server.', $response, 0, $e);
        }

        if (!$data['resultat']) {
            $errors = \is_array($data['erreurs']) ? implode(',', $data['erreurs']) : $data['erreurs'];
            throw new TransportException(sprintf('[HTTP %d] Unable to send the SMS: error(s) "%s".', $response->getStatusCode()$errors)$response);
        }

        $sentMessage = new SentMessage($message(string) $this);
        $sentMessage->setMessageId($data['id']);

        return $sentMessage;
    }
}
// @see https://www.w3.org/TR/activitystreams-core/#jsonld         $update = new Update($options->getTopics() ?? $this->topics, json_encode([
            '@context' => 'https://www.w3.org/ns/activitystreams',
            'type' => 'Announce',
            'summary' => $message->getSubject(),
        ])$options->isPrivate()$options->getId()$options->getType()$options->getRetry());

        try {
            $messageId = $this->hub->publish($update);

            $sentMessage = new SentMessage($message(string) $this);
            $sentMessage->setMessageId($messageId);

            return $sentMessage;
        } catch (MercureRuntimeException|InvalidArgumentException $e) {
            throw new RuntimeException('Unable to post the Mercure message: '.$e->getMessage()$e->getCode()$e);
        }
    }
}
if (200 !== $statusCode) {
            throw new TransportException(sprintf('Unable to send the Ntfy push notification: "%s".', $response->getContent(false))$response);
        }

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

        if (empty($result['id'])) {
            throw new TransportException(sprintf('Unable to send the Ntfy push notification: "%s".', $response->getContent(false))$response);
        }

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

        return $sentMessage;
    }

    public function supports(MessageInterface $message): bool
    {
        return $message instanceof PushMessage &&
            (null === $message->getOptions() || $message->getOptions() instanceof NtfyOptions);
    }

    

    public function testSendToTransportDefinedByMessage()
    {
        $transports = new Transports([
            'one' => $one = $this->createMock(TransportInterface::class),
        ]);

        $message = new ChatMessage('subject');

        $one->method('supports')->with($message)->willReturn(true);

        $one->expects($this->once())->method('send')->willReturn(new SentMessage($message, 'one'));

        $sentMessage = $transports->send($message);

        $this->assertSame($message$sentMessage->getOriginalMessage());
        $this->assertSame('one', $sentMessage->getTransport());
    }

    public function testSendToFirstSupportedTransportIfMessageDoesNotDefineATransport()
    {
        $transports = new Transports([
            'one' => $one = $this->createMock(TransportInterface::class),
            
try {
            $data = $response->toArray(false);
        } catch (ExceptionInterface) {
            throw new TransportException('Unable to send the SMS.', $response);
        }

        if (isset($data['code']) && 0 !== (int) $data['code']) {
            throw new TransportException(sprintf('Unable to send SMS: "Code: "%s". Message: "%s"".', $data['code']$data['msg'] ?? 'Unknown reason')$response);
        }

        return new SentMessage($message(string) $this);
    }
}
$errorMessage = $jsonContents['results'][0]['error'];
        } elseif (200 !== $statusCode) {
            $errorMessage = $response->getContent(false);
        }

        if (null !== $errorMessage) {
            throw new TransportException('Unable to post the Firebase message: '.$errorMessage$response);
        }

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

        $sentMessage = new SentMessage($message(string) $this);
        $sentMessage->setMessageId($success['results'][0]['message_id'] ?? '');

        return $sentMessage;
    }
}

        $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);
        }

        return $message;
    }
}
Home | Imprint | This part of the site doesn't use cookies.