if (!
$message instanceof ChatMessage
) { throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::
class,
$message);
} $options =
$message->
getOptions()?->
toArray() ??
[];
$bodyBuilder =
new ChatworkMessageBodyBuilder();
if (\
array_key_exists('to',
$options)) { $bodyBuilder->
to($options['to'
]);
} if (\
array_key_exists('selfUnread',
$options)) { $bodyBuilder->
selfUnread($options['selfUnread'
]);
} $messageBody =
$bodyBuilder ->
body($message->
getSubject()) ->
getMessageBody();
$endpoint =
sprintf('https://%s/v2/rooms/%s/messages',
$this->
getEndpoint(),
$this->roomId
);
$response =
$this->client->
request('POST',
$endpoint,
[ 'body' =>
$messageBody,
'headers' =>
[ 'X-ChatWorkToken' =>
$this->apiToken,
],