Giter VIP home page Giter VIP logo

laravel-viber-bot's Introduction

Viber Bot

Latest Version StyleCI

Installation

This package can be installed through Composer.

composer require mprince/laravel-viber-bot

In Laravel 5.5 and above the package will autoregister the service provider. In Laravel 5.4 you must install this service provider.

// config/app.php
'providers' => [
    ...
    Paragraf\ViberBot\ViberBotServiceProvider::class,
    ...
];

Changelog

Please see CHANGELOG for more information what has changed recently.

Configuration

You need to set in .env and setup webhook.

Env

VIBERBOT_API=your_viber_token
VIBERBOT_NAME=name
VIBERBOT_PHOTO=photo

You can find Viber token on Viber Partners after creating bot on Info tab.

WebHook

You must run artisan command for webhoook with url parameter

php artisan viber-bot:webhook https://example-url.com/some-route

Note: It must be full url and must be HTTPS.

Config file

Optionally, you can publish the config file of this package with this command:

php artisan vendor:publish --provider="Paragraf\ViberBot\ViberBotServiceProvider"

The following config file will be published in config/viberbot.php

Usage

When the installation is done you have access to Bot and Client class.

Bot class

With bot class you naivgate your ViberBot how to work.

(new Bot($request, new TextMessage()))
  ->on(new MessageEvent($request->timestamp, $request->message_token, 
  new ViberUser($request->sender['id'],$request->sender['name']), $request->message))
  ->hears("Hi!")
  ->replay("Hello World!")
  ->send();

Note: If viber user not set name you will get error.

You can change responding type Message and Event who listen that event.

API Accept Description
on(new MessageEvent(...)) Event object Listen specific Event
hears("Hi!") string, array, regex ViberBot listen key word Hi!, can be array for more words for one event
body($callback) callback ViberBot can do some business logic.
replay("Hello World!") string, array, Model ViberBot respond with Hello World!, can be array or Model
send() --- Send respond to Viber server.

List of Events:

  • ConversationStartedEvent
  • DeliveredEvent
  • FailedEvent
  • MessageEvent
  • SeenEvent
  • SubscribedEvent
  • UnsubscribedEvent

Note: If you don't want to listen all events you can change event_types in config/viberbot.php. If you change you must run again php artisan viber-bot:webhook your-url in oreder to apply changes.

List of Messages:

  • TextMessage
  • BroadcastMessage
  • ContactMessage
  • FileMessage
  • KeyboardMessage
  • LocationMessage
  • PictureMessage
  • StickerMessage
  • URLMessage
  • VideoMessage
  • WelcomeMessage
  • CarouselMessage - ToDo

Client class

Client class, provide to you extra utility.

 (new Client())->broadcast('Hello', User::all(), 'viber_id');
API Description
broadcast($text, $model, $method) Broadcast message to all subscribed user on Viber Chat, 300 users per request.
getUserDetails($user_id) Get details for specific user
getOnlineStatus(array $viberIds) Get online statuses for users, 100 users per request
getAccountInfo() Get account information (Your Public Account)
removeWebhook() Remove WebHook

Note: $method in broadcast() must point to viber_id. Also getOnlineStatus() need viber_ids.

If you want more information about Viber API or how something works check Viber REST API

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

laravel-viber-bot's People

Contributors

mprince2k18 avatar apolol avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.