PHP code example of assistly / laravel-channel

1. Go to this page and download the library: Download assistly/laravel-channel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

assistly / laravel-channel example snippets


final class OrgTenants implements TenantResolver
{
    public function credentials(string $tenantId): ?AssistlyCredentials
    {
        // null is a normal state: most tenants never connect Assistly.
    }

    public function mode(string $tenantId, string $threadId): ChannelMode
    {
        // Off | Analyze | Reply. Resolved per thread, so one conversation can
        // be silenced when an operator takes it over without changing anything
        // else about the tenant.
    }
}

final class SendViaGateway implements ReplyTransport
{
    public function deliver(ChannelReply $reply): void
    {
        // Use the sending path you already have, with its quotas and retries.
        // Throwing marks the queued job failed; swallowing the error would
        // report an answer the customer never saw.
    }
}

final class History implements ConversationSource
{
    public function history(string $tenantId, string $threadId, int $limit): iterable
    {
        // Oldest first. The caller trims to what Assistly will actually read,
        // so returning more than a few dozen is wasted work.
    }

    public function attachment(string $tenantId, string $externalMessageId): ?StreamInterface
    {
        // null means "not fetched yet", not "failed" — a host that mirrors
        // media lazily is retried rather than sent a message without its file.
    }
}

$this->app->singleton(TenantResolver::class, OrgTenants::class);
$this->app->singleton(ReplyTransport::class, SendViaGateway::class);
$this->app->singleton(ConversationSource::class, History::class);

$message = new InboundMessage(
    channel: config('assistly.channel'),
    externalId: $thread->id,          // your thread identifier
    externalMessageId: $incoming->id, // stable across retries — dedup depends on it
    text: $incoming->body,
    sentAt: $incoming->created_at->toDateTimeImmutable(),
);

$mode->answers()
    ? RequestAssistlyReply::dispatch($tenantId, $message)
    : RecordAssistlyMessage::dispatch($tenantId, $message);

Event::listen(ConversationHandedOff::class, PauseTheBot::class);
Event::listen(ConversationInsight::class, TagTheThread::class);
Event::listen(AssistlyUnavailable::class, AlertTheOperator::class);