MessagePart::fromArray( $array )

In this article

{@inheritDoc}

Source

public static function fromArray(array $array): self
{
    if (isset($array[self::KEY_CHANNEL])) {
        $channel = MessagePartChannelEnum::from($array[self::KEY_CHANNEL]);
    } else {
        $channel = null;
    }
    $thoughtSignature = $array[self::KEY_THOUGHT_SIGNATURE] ?? null;
    // Check which properties are set to determine how to construct the MessagePart
    if (isset($array[self::KEY_TEXT])) {
        return new self($array[self::KEY_TEXT], $channel, $thoughtSignature);
    } elseif (isset($array[self::KEY_FILE])) {
        return new self(File::fromArray($array[self::KEY_FILE]), $channel, $thoughtSignature);
    } elseif (isset($array[self::KEY_FUNCTION_CALL])) {
        return new self(FunctionCall::fromArray($array[self::KEY_FUNCTION_CALL]), $channel, $thoughtSignature);
    } elseif (isset($array[self::KEY_FUNCTION_RESPONSE])) {
        return new self(FunctionResponse::fromArray($array[self::KEY_FUNCTION_RESPONSE]), $channel, $thoughtSignature);
    } else {
        throw new InvalidArgumentException('MessagePart requires one of: text, file, functionCall, or functionResponse.');
    }
}

Changelog

VersionDescription
0.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.