承接 nael_d/viberify 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nael_d/viberify

Composer 安装命令:

composer require nael_d/viberify

包简介

Viberify simplifies sending messages (text, images, videos, files, contacts, locations, URLs, and stickers), managing webhooks, and retrieving account information for your Viber Channel.

README 文档

README

Viberify is a simple PHP library for interacting with the Viber Channel API, allowing you to send messages, media, contacts, URLs, locations, and more, to your Viber Channel.

Features

  • PHP Compatibility: Works with PHP >= 7.0.0 minimum.
  • Easy Authentication: Set up your Viber Channel's authentication token and Viber ID to start interacting with the Viber API.
  • Webhook Integration: Set a secure webhook URL to receive callbacks and user messages.
  • Account Info Retrieval: Fetch details about your Viber Channel's account, including editable fields from the Viber app.
  • Error Handling: Includes built-in error handling for issues with Viber API responses.
  • Multiple Message Types: Send a variety of message types, including:
    • Text messages (up to 7000 characters).
    • Image messages (JPEG format, up to 1MB).
    • Video messages (MP4/H264 format, up to 50MB).
    • File messages (up to 50MB with proper extensions).
    • Contact card information.
    • Location coordinates (via Google Maps).
    • URL links with optional descriptions.
    • Stickers (by ID).

Table of Contents

Prerequisites

  • Viber Channel: Only superadmins of a Viber Channel can access the API.
  • Viber Version: Ensure you're using Viber version 17.7 or higher.
  • Authentication Token: Obtain the authentication token for your Viber Channel from the Viber Developer Tools page.

Installation

Viberify is available to be installed through Composer:

composer require nael_d/viberify

You are also able to download Viberify manually. Download Viberify and require src/Viberify.php.

For a better release checking, we may suggest to review Releases page to pick up and review developing timeline, as it provides a clear listing of versions along with detailed descriptions of each release.

Getting Started

Once installed, the class Viberify is ready for you.

💡 Viberify class is available under Viberify namespace.

The first thing that you need before you go on, you have to obtain the Authentication token key of your targeted channel:

Viber Desktop

Then copy the Authentication token:

Authentication Token

API Methods

Viberify provides a set of methods to interact with the Viber Channel API, allowing you to send various types of content and manage your channel. Below is an overview of the available methods:

  • set_auth_token:

    Once copied your Authentication token, initialize Viberify with your token to get started:

    \Viberify\Viberify::set_auth_token("VIBER_AUTH_TOKEN");
    

    It's a good practice to store it in an .env file for a better flexible managing:

    \Viberify\Viberify::set_auth_token(env('VIBER_AUTH_TOKEN'));
    
  • set_webhook:

    Sets the webhook URL for your Viber Channel. The webhook will be used to receive callbacks and messages from users.

    Parameters:

    • string $webhook: The webhook URL (must use HTTPS).

    Usage:

    \Viberify\Viberify::set_webhook('https://your-webhook-url.com/target');
    

    💡 You only need to call this method once. No need to recall it each time.

    💡 For more info about Viber Webhooks, refer to Setting a Webhook page to know more.

  • get_account_info:

    Fetches the details of your Viber channel as registered with Viber. This helps you to get your Viber unique ID.

    Usage:

    $account_info = \Viberify\Viberify::get_account_info();
    $viber_id     = $account_info['members'][0]['id'];
    
    /**
     * array(6) {
        ["status"]=>
        int(0)
        ["status_message"]=>
        string(2) "ok"
        ["id"]=>
        string(22) "pa:0000000000000000000"
        ["chat_hostname"]=>
        string(11) "SN-CHAT-01_"
        ["name"]=>
        string(12) "Demo Channel"
        ["members"]=>
        array(1) {
          [0]=>
          array(4) {
            ["id"]=>
            string(24) "QerXFUgfdI45gfdBdfMZKq=="
            ["name"]=>
            string(11) "Viber's account name"
            ["avatar"]=>
            string(208) "https://media-direct.cdn.viber.com/download_photo?fltp=jpg"
            ["role"]=>
            string(10) "superadmin"
          }
        }
      }
     */
    

    💡 It's a better practise to copy your account's id rather than call this method to gain it repeatedly each time you perform an action to avoid duplicated requests.

    💡 You only need to call this method once you've prepared Viberify to get your account's id. No need to call it later when unneeded.

  • set_viber_id:

    Sets the Viber ID representing the Viber account that will appear as the sender.

    Parameters:

    • string $viber_id: The Viber ID of the superadmin account gained from get_account_info().

    Usage:

    \Viberify\Viberify::set_viber_id('YOUR_VIBER_ID');
    
  • send_message:

    Send a textual message to the Viber Channel.

    Parameters:

    • string $message: Required. The message text (max 7000 characters).

    Usage:

    \Viberify\Viberify::send_message('Hello, Viber!');
    
  • send_image:

    Send a picture message to the Viber Channel.

    Parameters:

    • string $image: Required, max size 1MB. URL of the image (JPEG). Only JPEG format is supported. The URL must have a resource with a .jpeg file extension.
    • string $message: Optional, max 768 characters. Description of the photo.
    • string $thumb: Optional, max size 100kb, Recommended dimensions is 400x400. Only JPEG format is supported.

    Usage:

    \Viberify\Viberify::send_image(
      'https://example.com/image.jpeg',
      'Here is an image!',
      'https://example.com/thumb.jpeg'
    );
    
  • send_video:

    Send a video message to the Viber Channel.

    Parameters:

    • string $video: Required, max size 50MB. Only MP4 and H264 are supported.
    • float $size: Required, in MBs. Size of the video in MB.
    • int $duration: Optional, max 180 seconds. Video duration in seconds; will be displayed to the receiver.
    • string $message: Optional, max 768 characters. Description of the video.
    • string $thumb: Optional, max size 100kb, Recommended dimensions is 400x400. URL of a reduced size image (JPEG). Only JPEG format is supported.

    Usage:

    \Viberify\Viberify::send_video(
      'https://example.com/video.mp4',
      15,
      120,
      'Video description',
      'https://example.com/thumb.jpeg'
    );
    
  • send_file:

    Send a file message to the Viber Channel.

    Parameters:

    • string $file: Required, max size 50MB. See forbidden file formats for unsupported file types.
    • float $size: Required, in MBs. Size of the file in MB.
    • string $filename: Required, max 256 characters (including file extension). File name should include extension. Sending a file without extension or with the wrong extension might cause the client to be unable to open the file.

    Usage:

    \Viberify\Viberify::send_file('https://example.com/file.zip', 25.81, 'file.zip');
    
  • send_contact:

    Send a contact message to the Viber Channel.

    Parameters:

    • string $name: Required, max 28 characters. Name of the contact.
    • string $phone_number: Required, max 18 characters. Phone number of the contact.

    Usage:

    \Viberify\Viberify::send_contact('John Doe', '+123456789012345');
    
  • send_location:

    Send a Google Maps location message to the Viber Channel.

    Parameters:

    • string $lat: Required, range between ±90°. Location coordinates.
    • string $lon: Required, range between ±180°. Location coordinates.

    Usage:

    // San Francisco coordinates
    \Viberify\Viberify::send_location('37.7749', '-122.4194');
    
  • send_url:

    Send a URL message to the Viber Channel.

    Parameters:

    • string $link: Required, max 2,000 characters. URL link.
    • string $message: Optional, max 120 characters. Description of the URL.

    Usage:

    \Viberify\Viberify::send_url('https://example.com', 'Check out this link!');
    
  • send_sticker:

    Send a sticker message. See full list of stickers IDs.

    Parameters:

    • string $sticker_id: Required. Unique Viber sticker ID.

    Usage:

    \Viberify\Viberify::send_sticker(46105);
    

Error Handling

If there is an issue with the request, the library will return a status code and message indicating the error. For more details on error codes, refer to the Viber API Error Codes page.

Notes

  • Forbidden File Formats: Viber restricts certain file formats from being uploaded. Refer to the forbidden file formats documentation for a full list of unsupported file types.
  • SSL Requirements: The webhook URL must use HTTPS with a valid SSL certificate. Viber does not support self-signed certificates.

Conclusion

The main purpose of Viberify is to simplify the process of publishing content to your Viber Channel, allowing you to automate message delivery to all your subscribers directly from your website.

Whether you're sharing text updates, images, videos, or files, Viberify makes it easy to programmatically engage with your Viber audience at scale.

By integrating this library, you can streamline content distribution and communication, ensuring seamless interaction with your channel’s subscribers.

License

This project is licensed under the Mozilla Public License 2.0 (MPL-2.0). You are free to use, modify, and distribute this library under the terms of the MPL-2.0. See the LICENSE file for details.

Made with ❤️ by Nael Dahman

nael_d/viberify 适用场景与选型建议

nael_d/viberify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「api」 「sdk」 「messaging」 「webhook」 「php-library」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nael_d/viberify 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nael_d/viberify 我们能提供哪些服务?
定制开发 / 二次开发

基于 nael_d/viberify 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2024-11-24