2017 © Pedro Pelรกez
 

library viber-bot-php

Php bot interface to work with Viber API

image

bogdaan/viber-bot-php

Php bot interface to work with Viber API

  • Sunday, April 22, 2018
  • by Bogdan
  • Repository
  • 23 Watchers
  • 125 Stars
  • 8,670 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 54 Forks
  • 11 Open issues
  • 13 Versions
  • 23 % Grown

The README.md

PHP sdk for Viber api

Build
Status, (*1)

Library to develop a bot for the Viber platform. Create you first Viber bot step by step, see demo at viber://pa?chatURI=viber-bot-php&context=github.com, (*2)

Installation

composer require bogdaan/viber-bot-php

Example

<?php

require_once("../vendor/autoload.php");

use Viber\Bot;
use Viber\Api\Sender;

$apiKey = '<PLACE-YOU-API-KEY-HERE>';

// reply name
$botSender = new Sender([
    'name' => 'Whois bot',
    'avatar' => 'https://developers.viber.com/img/favicon.ico',
]);

try {
    $bot = new Bot(['token' => $apiKey]);
    $bot
    ->onConversation(function ($event) use ($bot, $botSender) {
        // this event fires if user open chat, you can return "welcome message"
        // to user, but you can't send more messages!
        return (new \Viber\Api\Message\Text())
            ->setSender($botSender)
            ->setText("Can i help you?");
    })
    ->onText('|whois .*|si', function ($event) use ($bot, $botSender) {
        // match by template, for example "whois Bogdaan"
        $bot->getClient()->sendMessage(
            (new \Viber\Api\Message\Text())
            ->setSender($botSender)
            ->setReceiver($event->getSender()->getId())
            ->setText("I do not know )")
        );
    })
    ->run();
} catch (Exception $e) {
    // todo - log exceptions
}

See more in examples directory., (*3)

Library structure

.
โ”œโ”€โ”€ Api
โ”‚ย ย  โ”œโ”€โ”€ Entity.php               
โ”‚ย ย  โ”œโ”€โ”€ Event                     # all remote events ("callbacks")
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Conversation.php      # fires when user open 1v1 chat
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Delivered.php         # fires when message delivered (for each device)
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Factory.php           # Event factory
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Failed.php            # fires when delivery failed (for each device)
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Message.php           # fires when user send message
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Seen.php              # fires when user read message (for each device)
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Subscribed.php        # fires when user subscribe to PA
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Type.php              # available types
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ Unsubscribed.php      # fires when user unsubscribed
โ”‚ย ย  โ”œโ”€โ”€ Event.php                 # base class for all events
โ”‚ย ย  โ”œโ”€โ”€ Exception                 #
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ ApiException.php      # remote or logic error
โ”‚ย ย  โ”œโ”€โ”€ Keyboard                  #
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ Button.php            # all types of buttons here
โ”‚ย ย  โ”œโ”€โ”€ Keyboard.php              # button container
โ”‚ย ย  โ”œโ”€โ”€ Message                   #
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ CarouselContent.php   #
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Contact.php           #
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Factory.php           #
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ File.php              #
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Location.php          #
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Picture.php           #
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Sticker.php           #
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Text.php              #
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Type.php              # available message types
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Url.php               #
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ Video.php             #
โ”‚ย ย  โ”œโ”€โ”€ Message.php               # base class for all messages
โ”‚ย ย  โ”œโ”€โ”€ Response.php              # wrap api response
โ”‚ย ย  โ”œโ”€โ”€ Sender.php                # represent bot-sender
โ”‚ย ย  โ”œโ”€โ”€ Signature.php             # signature helper (verify or create sign)
โ”‚ย ย  โ”œโ”€โ”€ User                      #
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ State.php             # user state (online/offline etc)
โ”‚ย ย  โ””โ”€โ”€ User.php                  # viber user
โ”œโ”€โ”€ Bot                           #
โ”‚ย ย  โ””โ”€โ”€ Manager.php               # manage bot closures
โ”œโ”€โ”€ Bot.php                       # bot class
โ””โ”€โ”€ Client.php                    # api client

Read more

Features

  • [x] all api entities
  • [x] validate request and response signs
  • [x] provide webhook interface
  • [x] provide event interface
  • [ ] wrap all api response to entities
  • [ ] validate api entities before submit?
  • [ ] implement log levels with monolog?
  • [ ] post on public page

Contributing

Pull requests are welcome., (*4)

The Versions

22/04 2018

dev-develop

dev-develop

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

22/04 2018

dev-master

9999999-dev

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

22/04 2018

0.0.12

0.0.12.0

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

29/12 2017

0.0.11

0.0.11.0

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

16/11 2017

0.0.10

0.0.10.0

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

05/11 2017

0.0.9

0.0.9.0

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

31/10 2017

0.0.8

0.0.8.0

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

30/10 2017

0.0.6

0.0.6.0

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

24/10 2017

0.0.5

0.0.5.0

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

16/10 2017

0.0.4

0.0.4.0

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

11/10 2017

0.0.3

0.0.3.0

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

05/02 2017

0.0.2

0.0.2.0

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber

04/02 2017

0.0.1

0.0.1.0

Php bot interface to work with Viber API

  Sources   Download

MIT

The Requires

 

The Development Requires

bot im viber