2017 © Pedro Peláez
 

symfony-bundle simple-skype-bot

image

tobur/simple-skype-bot

  • Wednesday, March 7, 2018
  • by Tobur
  • Repository
  • 1 Watchers
  • 1 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Install, (*1)

composer require tobur/simple-skype-bot
SimpleSkypeBot\SimpleSkypeBotBundle::class => ['all' => true]
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

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

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

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

simple_skype_bot:
  token_class: 'App\Entity\SkypeToken'
  user_class: 'App\Entity\SkypeUser'
  client_id: 'some client id'
  client_secret: 'some secret'

You should create application and bot on https://dev.botframework.com/bots/new., (*2)

Put your endpoint to the main route., (*3)

skype_endpoint:
    resource: '@SimpleSkypeBotBundle/Resources/config/routing.yaml'
    prefix: /

For your bot you should setup api endpoint. For develop you can use http tunnel with https://ngrok.com/., (*4)

./ngrok http 80

Like example for dev you can use: https://somecode.ngrok.io/api/messages, (*5)

Add you bot to skype. https://join.skype.com/bot/your-code-here, (*6)

Example how to handle messages, (*7)

<?php

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);
    }
}

Some default skype command, put it to the skype with your bot:, (*8)

.save my_skype_login

Than you can use:, (*9)

php bin/console simply-skype-bot:send-message my_skype_login Hi

The Versions