californiamountainsnake/longmantelegrambot-utils

This package is abandoned and no longer maintained. No replacement package was suggested.

This is the set of util traits intended for the longman/telegram-bot library!

1.1.24 2020-01-31 06:10 UTC

README

This is the set of util traits intended for the longman/telegram-bot library!

Functionality:

  • Easily send text messages in one line.

Install:

Require this package with Composer

Install this package through Composer. Edit your project's composer.json file to require californiamountainsnake/longmantelegrambot-utils:

{
    "name": "yourproject/yourproject",
    "type": "project",
    "require": {
        "php": "^7.2",
        "californiamountainsnake/longmantelegrambot-utils": "*"
    }
}

and run composer update

or

run this command in your command line:

composer require californiamountainsnake/longmantelegrambot-utils

Usage:

  1. Create your custom bot command as usual.
  2. Use needed traits and realise the abstract traits' methods:
<?php
class TestCommand extends Command
{
    use TelegramUtils;
    use SendUtils;
    use ConversationUtils;


    /**
     * @var Conversation|null
     */
    protected $conversation;


    public function getTelegramMessage(): ?Message
    {
        return $this->getMessage();
    }

    protected function getStateNoteName(): string
    {
        return 'state';
    }

    protected function getConversation(): ?Conversation
    {
        return $this->conversation;
    }

    protected function setConversation(?Conversation $_new_conversation_state): void
    {
        $this->conversation = $_new_conversation_state;
    }

    /**
     * Execute command
     *
     * @return ServerResponse
     * @throws TelegramException
     */
    public function execute(): ServerResponse
    {
        return $this->sendTextMessage('Test!');
    }
}