PHP code example of tobur / simple-skype-bot

1. Go to this page and download the library: Download tobur/simple-skype-bot 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/ */

    

tobur / simple-skype-bot example snippets




namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="skype_token")
 */
class SkypeToken extends \SimpleSkypeBot\Model\SkypeToken
{
}



namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="skype_user")
 */
class SkypeUser extends \SimpleSkypeBot\Model\SkypeUser
{
}




namespace App\Subscriber;

use SimpleSkypeBot\DTO\MessageDTO;
use SimpleSkypeBot\Event\NewMessageEvent;
use SimpleSkypeBot\Exceptions\SimpleSkypeBotException;
use SimpleSkypeBot\Service\SkypeBotManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class SkypeSubscriber implements EventSubscriberInterface
{
    /**
     * @var SkypeBotManager
     */
    protected $botManager;

    /**
     * @param SkypeBotManager $botManager
     */
    public function __construct(SkypeBotManager $botManager) {
        $this->botManager = $botManager;
    }

    /**
     * @return array
     */
    public static function getSubscribedEvents()
    {
        return [
            NewMessageEvent::NAME => 'handleNewMessage'
        ];
    }

    /**
     * @param NewMessageEvent $event
     * @throws SImpleSkypeBotException
     * @throws \Doctrine\ORM\ORMException
     * @throws \Doctrine\ORM\OptimisticLockException
     * @throws \SimpleSkypeBot\Service\SimpleSkypeBotException
     */
    public function handleNewMessage(NewMessageEvent $event)
    {
        /** @var MessageDTO $messageDTO */
        $messageDTO = $event->getData();
        $messageDTO->setText('Hello man!');
        $this->botManager->sendMessage($messageDTO);
    }
}