californiamountainsnake/longmantelegrambot-inlinecalendar

该包已被弃用,不再维护。未建议替代包。

这是一个以内嵌键盘形式的日历。

1.4.3 2021-05-03 11:15 UTC

This package is auto-updated.

Last update: 2022-05-31 00:18:57 UTC


README

这是一个以内嵌键盘形式的日历,用于与 longman/telegram-botcaliforniamountainsnake/longmantelegrambot-inlinemenu 库一起使用。 Calendar screenshot

安装

使用 Composer 需求此包

通过 Composer 安装此包。编辑您项目的 composer.json 文件,以需求 californiamountainsnake/longmantelegrambot-inlinecalendar

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

并运行 composer update

或者

在命令行中运行此命令

composer require californiamountainsnake/longmantelegrambot-inlinecalendar

用法

  1. 将特质包含到您的机器人命令中并实现抽象方法(主要包含语言字符串)
<?php
class TestCommand extends BaseUserCommand
{
    use InlineCalendar;
}
  1. 创建日历配置
<?php
class TestCommand extends BaseUserCommand
{
    use InlineCalendar;
    
    private function getCalendarConfig(): CalendarConfig
    {
        $min = [2019, 8, 28];
        $max = [2037, 12, 31];
        $def = $min;
        return new CalendarConfig('Date selection', $min, $max, $def);
    }
}
  1. 使用日历!
<?php
class TestCommand extends BaseUserCommand
{
    use InlineCalendar;
    
    public function execute(): ServerResponse
    {
        // Conversation start
        $this->startConversation();

        $isSelected = $this->selectDate($this->getCalendarConfig(), 'Please select the date:', $this->getMessage());
        if (!$isSelected) {
            return $this->emptyResponse();
        }
        
        $msg = $this->sendTextMessage (\print_r($this->getCalendarDate($this->getCalendarConfig()), true));
        $this->stopConversation();
        return $msg;
    }
}