Skip to main content

RespectifyClientAsync

RespectifyClientAsync lets you interact with the Respectify API. It is asynchronous, meaning you need to run the event loop to get results. This is important for high-performance applications.

This uses ReactPHP under the hood, and you must call the run() method to run the event loop (if it's not already running) after you call the API methods in order to resolve the promises that this API returns.

See the Quick Start for sample code.

  • Full name: \Respectify\RespectifyClientAsync

Methods

__construct

Create an instance of the async Respectify API client.

public __construct(string $email, string $apiKey): self

Parameters:

ParameterTypeDescription
$emailstringAn email address.
$apiKeystringA hex string representing the API key.

initTopicFromText

Initialize a Respectify topic, using plain text or Markdown.

public initTopicFromText(string $text): \React\Promise\PromiseInterface<string>

Parameters:

ParameterTypeDescription
$textstringThe text content to initialize the topic.

Return Value:

A promise that resolves to the article ID. This is a string containing a UUID. You must keep this (eg, store it in a database) to use in future when evaluating comments written about this topic.

Throws:

initTopicFromUrl

Initialize a Respectify topic with the contents of a URL.

public initTopicFromUrl(string $url): \React\Promise\PromiseInterface<string>

The URL must be publicly accessible. It can point to any text, Markdown, HTML, or PDF file.

Parameters:

ParameterTypeDescription
$urlstringThe URL pointing to the content to initialize the topic.

Return Value:

A promise that resolves to the article ID as a UUID string.

Throws:

evaluateComment

Evaluate a comment in the context of the article/blog/etc the conversation is about, and optionally the comment it is replying to.

public evaluateComment(string $articleContextId, string $comment, string|null $replyToComment = null): \React\Promise\PromiseInterface<\Respectify\CommentScore>

This is Respectify's main API and the one you will likely call the most. It returns a promise to a CommentScore object which has a wide variety of information and assessments.

See the Quick Start for code samples showing how to use this.

Parameters:

ParameterTypeDescription
$articleContextIdstringa string containing UUID that identifies the article/blog/etc that this comment was written in the context of. This is the value you get by calling initTopicFromText or initTopicFromUrl.
$commentstringThe comment text: this is what is evaluated.
$replyToCommentstring|nullProvides additional context: the comment to which the one being evaluated is a reply. This is optional.

Return Value:

A promise that resolves to a CommentScore object.

Throws:

run

Run the ReactPHP event loop. This allows other tasks to run while waiting for Respectify API responses.

public run(): void

This must be called so that the promises resolve.