定制 omniai/sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

omniai/sdk

最新稳定版本:v1.0.2

Composer 安装命令:

composer require omniai/sdk

包简介

Official PHP SDK for OmniAI API

README 文档

README

Official PHP SDK for the OmniAI API - Multi-channel messaging platform with AI automation.

Installation

composer require omniai/sdk

Requirements

  • PHP >= 7.4
  • Composer
  • guzzlehttp/guzzle >= 7.0

Quick Start

<?php

require 'vendor/autoload.php';

use OmniAI\Client;

// Initialize client
$client = new Client('YOUR_API_KEY');

// Send a message
$message = $client->messages->send([
    'phone' => '+5511999999999',
    'channel' => 'whatsapp',
    'type' => 'text',
    'content' => 'Olá! Como posso ajudar?'
]);

echo "Message sent: {$message['id']}\n";

Features

  • Multi-channel messaging - WhatsApp, Email, SMS, Telegram
  • Contact management - Create, update, search contacts
  • Campaign automation - Schedule and manage marketing campaigns
  • AI-powered features - Chat completions, sentiment analysis, intent detection
  • Analytics & Reports - Get insights and export reports
  • PSR-4 Autoloading - Modern PHP standards
  • Error handling - Comprehensive exception classes

Usage Examples

Send Messages

// Text message
$message = $client->messages->send([
    'phone' => '+5511999999999',
    'channel' => 'whatsapp',
    'type' => 'text',
    'content' => 'Hello from OmniAI!'
]);

// Media message
$mediaMessage = $client->messages->send([
    'phone' => '+5511999999999',
    'channel' => 'whatsapp',
    'type' => 'image',
    'content' => 'Check this image',
    'mediaUrl' => 'https://example.com/image.jpg'
]);

// Bulk send
$result = $client->messages->sendBulk([
    'messages' => [
        [
            'phone' => '+5511999999999',
            'channel' => 'whatsapp',
            'type' => 'text',
            'content' => 'Message 1'
        ],
        [
            'phone' => '+5511888888888',
            'channel' => 'whatsapp',
            'type' => 'text',
            'content' => 'Message 2'
        ]
    ]
]);

Manage Contacts

// Create contact
$contact = $client->contacts->create([
    'name' => 'João Silva',
    'phone' => '+5511999999999',
    'email' => 'joao@example.com',
    'tags' => ['customer', 'vip']
]);

// List contacts
$contacts = $client->contacts->list([
    'page' => 1,
    'limit' => 50,
    'search' => 'João'
]);

// Update contact
$updated = $client->contacts->update('contact-123', [
    'tags' => ['customer', 'vip', 'premium']
]);

Create Campaigns

$campaign = $client->campaigns->create([
    'name' => 'Black Friday 2024',
    'channel' => 'whatsapp',
    'messageTemplate' => 'Aproveite 50% OFF em todos os produtos!',
    'targetAudience' => [
        'tags' => ['customer'],
        'segment' => 'active'
    ],
    'scheduledAt' => '2024-11-29T09:00:00Z'
]);

// Start campaign
$client->campaigns->start($campaign['id']);

AI Features

// Chat completion
$response = $client->ai->chatCompletion([
    'messages' => [
        ['role' => 'user', 'content' => 'Preciso de ajuda com meu pedido']
    ]
]);

// Sentiment analysis
$sentiment = $client->ai->analyzeSentiment([
    'text' => 'Estou muito satisfeito com o atendimento!'
]);
echo $sentiment['sentiment']; // 'positive'

// Intent detection
$intent = $client->ai->extractIntent([
    'text' => 'Quero cancelar minha assinatura'
]);
echo $intent['intent']; // 'cancel_subscription'

// Generate response
$suggestion = $client->ai->generateResponse([
    'context' => 'Cliente perguntou sobre prazo de entrega',
    'userMessage' => 'Quando chega meu pedido?',
    'tone' => 'professional'
]);

Analytics

// Get overview
$analytics = $client->analytics->getOverview([
    'startDate' => '2024-01-01',
    'endDate' => '2024-01-31',
    'channel' => 'whatsapp'
]);

// Export report
$export = $client->analytics->exportReport([
    'reportType' => 'messages',
    'startDate' => '2024-01-01',
    'endDate' => '2024-01-31',
    'format' => 'pdf'
]);
echo $export['downloadUrl'];

Error Handling

use OmniAI\Client;
use OmniAI\Exceptions\AuthenticationException;
use OmniAI\Exceptions\ValidationException;
use OmniAI\Exceptions\RateLimitException;

$client = new Client('YOUR_API_KEY');

try {
    $message = $client->messages->send([
        'phone' => '+5511999999999',
        'channel' => 'whatsapp',
        'type' => 'text',
        'content' => 'Hello!'
    ]);
} catch (AuthenticationException $e) {
    echo 'Invalid API key';
} catch (ValidationException $e) {
    echo "Validation error: {$e->getMessage()}";
} catch (RateLimitException $e) {
    echo 'Rate limit exceeded, please wait';
}

Configuration

// Custom configuration
$client = new Client(
    'YOUR_API_KEY',
    'https://api.omniaiassist.com/v1'
);

API Reference

Messages

  • $client->messages->send($params) - Send message
  • $client->messages->get($messageId) - Get message by ID
  • $client->messages->list($params) - List messages
  • $client->messages->sendBulk($params) - Send multiple messages

Contacts

  • $client->contacts->create($params) - Create contact
  • $client->contacts->get($contactId) - Get contact by ID
  • $client->contacts->list($params) - List contacts
  • $client->contacts->update($contactId, $params) - Update contact
  • $client->contacts->delete($contactId) - Delete contact

Campaigns

  • $client->campaigns->create($params) - Create campaign
  • $client->campaigns->get($campaignId) - Get campaign
  • $client->campaigns->list($params) - List campaigns
  • $client->campaigns->start($campaignId) - Start campaign
  • $client->campaigns->pause($campaignId) - Pause campaign
  • $client->campaigns->delete($campaignId) - Delete campaign

AI

  • $client->ai->chatCompletion($params) - Chat completion
  • $client->ai->analyzeSentiment($params) - Sentiment analysis
  • $client->ai->extractIntent($params) - Intent detection
  • $client->ai->generateResponse($params) - Generate response

Analytics

  • $client->analytics->getOverview($params) - Get overview
  • $client->analytics->getMessagesStats($params) - Messages stats
  • $client->analytics->getAIStats($params) - AI stats
  • $client->analytics->exportReport($params) - Export report

License

MIT License - see LICENSE file for details

Support

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-05