andreybolonin
Repos
389
Followers
40

Events

issue comment
[RFC] Switch from Yaml to PHP files for skeleton configurations

Yaml is more understandable and simply to reading by human Sounds bad (I remembered the configs in zf 🥲)

Created at 1 month ago
pull request opened
add method to inject EntityManager

| ? | ! |--- | --- | Type | improvement | BC Break | no | Fixed issues |

Summary

Adding ability to inject EntityManager if we use this php-telegram-bot into Symfony project

<?php

namespace App\TelegramCommand;

use App\Entity\Contact;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Request;

/**
 * User "/subscribe" command.
 *
 * Get weather info for any place.
 * This command requires an API key to be set via command config.
 */
class SubscribeCommand extends UserCommand
{
    /**
     * @var string
     */
    protected $name = 'subscribe';

    /**
     * @var string
     */
    protected $description = 'Start msg';

    /**
     * @var string
     */
    protected $usage = '/subscribe';

    /**
     * @var string
     */
    protected $version = '1.2.0';

    public function execute(): ServerResponse
    {
        $message = $this->getMessage();
        $chat_id = $message->getChat()->getId();
//        $user_id = $message->getFrom()->getId();
        $contactId = $message->getText(true);

        $contact = $this->telegram->em->getRepository(Contact::class)->findOneBy(['contactId' => $contactId]);

        if ($contactId) {
            $text = 'Отлично! Мы привязали чатбот к вашему ContactId';
        } else {
            $text = 'К сожалению, мы не смогли найти аккаунт по вашему ContactId';
        }

        $data = [
            'chat_id' => $chat_id,
            'text' => $text,
        ];

        return Request::sendMessage($data);
    }
}

Created at 2 months ago

add method to inject EntityManager

Created at 2 months ago
Created at 2 months ago