universal_bot-ts

Форк
0
79 строк · 3.2 Кб
1
import {TemplateTypeModel, BotController, mmApp, Buttons} from '../../../../../src';
2
import {UserButton} from '../Components/UserButton';
3
import {UserCard} from '../Components/UserCard';
4
import {UserSound} from '../Components/UserSound';
5

6
interface IUserApp {
7
    userId: string;
8
    data: {
9
        text: string
10
    };
11
}
12

13
export class UserApp extends TemplateTypeModel {
14
    /**
15
     * Инициализация параметров
16
     *
17
     * @param query
18
     * @param controller
19
     * @return bool
20
     * @see TemplateTypeModel::init() Смотри тут
21
     */
22
    public async init(query: string | IUserApp, controller: BotController): Promise<boolean> {
23
        if (query) {
24
            let content: IUserApp;
25
            if (typeof query === 'string') {
26
                content = <IUserApp>JSON.parse(query);
27
            } else {
28
                content = {...query}
29
            }
30
            this.controller = controller;
31
            this.controller.requestObject = content;
32
            /**
33
             * Инициализация основных параметров приложения
34
             */
35
            this.controller.userCommand = content.data.text;
36
            this.controller.originalUserCommand = content.data.text;
37

38
            this.controller.userId = 'Идентификатор пользователя. Берется из content';
39
            mmApp.params.user_id = this.controller.userId;
40
            return true;
41
        } else {
42
            this.error = 'UserApp:init(): Отправлен пустой запрос!';
43
        }
44
        return false;
45
    }
46

47
    /**
48
     * Отправка ответа пользователю
49
     *
50
     * @return {Promise<string>}
51
     * @see TemplateTypeModel::getContext() Смотри тут
52
     */
53
    public async getContext(): Promise<string> {
54
        // Проверяем отправлять ответ пользователю или нет
55
        if (this.controller.isSend) {
56
            /**
57
             * Отправляем ответ в нужном формате
58
             */
59
            const buttonClass = new UserButton();// Класс отвечающий за отображение кнопок. Должен быть унаследован от TemplateButtonTypes
60
            /*
61
             * Получение кнопок
62
             */
63
            const buttons = this.controller.buttons.getButtons(Buttons.T_USER_APP_BUTTONS, buttonClass);
64

65
            const cardClass = new UserCard();// Класс отвечающий за отображение карточек. Должен быть унаследован от TemplateCardTypes
66
            /*
67
             * Получить информацию о карточке
68
             */
69
            const cards = await this.controller.card.getCards(cardClass);
70

71
            const soundClass = new UserSound();// Класс отвечающий за отображение звуков. Должен быть унаследован от TemplateSoundTypes
72
            /*
73
             * Получить все звуки
74
             */
75
            const sounds = await this.controller.sound.getSounds('', soundClass);
76
        }
77
        return 'ok';
78
    }
79
}
80

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.