selfUnread example

$builder = new ChatworkMessageBodyBuilder();
        $builder->to(['abc', 'def']);
        $property = new \ReflectionProperty($builder, 'to');
        $this->assertSame(['abc', 'def']$property->getValue($builder));
        $builder->to('ghi');
        $this->assertSame(['ghi']$property->getValue($builder));
    }

    public function testSetSelfUnread()
    {
        $builder = new ChatworkMessageBodyBuilder();
        $builder->selfUnread(true);
        $property = new \ReflectionProperty($builder, 'selfUnread');
        $this->assertTrue($property->getValue($builder));
    }

    public function testSetBody()
    {
        $builder = new ChatworkMessageBodyBuilder();
        $builder->body('test body');
        $property = new \ReflectionProperty($builder, 'body');
        $this->assertEquals('test body', $property->getValue($builder));
    }

    
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,
            ],
$options = new ChatworkOptions();
        $options->to(['abc', 'def']);
        $this->assertSame(['to' => ['abc', 'def']]$options->toArray());

        $options->to('ghi');
        $this->assertSame(['to' => 'ghi']$options->toArray());
    }

    public function testSetSelfUnread()
    {
        $options = new ChatworkOptions();
        $options->selfUnread(true);
        $this->assertSame(['selfUnread' => true]$options->toArray());
    }
}
Home | Imprint | This part of the site doesn't use cookies.