Esempio n. 1
0
def add_kb(i, keyboard={}):
    print("user creates new button")
    # that's the default button name
    but_name = 'rename me'
    # here's the magic! your action can be generated in runtime
    # and with any local to that action parameters you want!
    func = gen_handler(but_name)
    keyboard.update({but_name: h.action(func)})
    # forward to THANKS state and update data. Upd_id is used in THANKS
    return States.THANKS, {'keyboard': keyboard, 'upd_id': but_name}
Esempio n. 2
0
def upd_kb(i, keyboard={}, upd_id='rename me'):
    but_name = i.text
    print('user changes name to ', but_name)
    # delete old button
    del keyboard[upd_id]
    # create a button with new name
    keyboard.update({
        # the format is ad in UI - {"NAME":tgf.action}
        but_name: h.action(gen_handler(but_name))
    })
    # forward to THANKS state and update data. Upd_id is used in THANKS
    return States.THANKS, {'keyboard': keyboard, 'upd_id': but_name}
Esempio n. 3
0
            h.post(lambda s, **d: d.get('keyboard', {}))
            # Some fancy magic will be done by tgflow above.
            # Before this state is passed, all h.post will be evaluated.
            # This h.post will return an array of buttons

            # tgflow will automatically add the persistent button to
            # ones that are returned by h.post!
        ]
    },
    States.MODIFY_BUT: {
        't': 'Send me the name of button',
        'b': [{
            'cancel': tgf.action(States.START)
        }],
        # now every time user sends us some text, upd_kb will be called
        'react': h.action(upd_kb, react_to='text'),
    },
    States.THANKS: {
        't': h.st('Youve modified, new name is %s', 'upd_id'),
        'b': [
            {
                'back to start': tgf.action(States.START)
            },
        ],
        # this is to stop triggering the previously defibed actiion for upd_kb
        'clear_trig': 'text'
    },
}

tgf.configure(
    token=key,
Esempio n. 4
0
class States(Enum):
    START = 1
    INFO = 2
    FAV = 3
    THANKS = 4


UI = {
    States.START: {
        't':
        'hello',
        'b': [{
            'show info': tgf.action(States.INFO)
        }, {
            'set my favourite': h.action(States.FAV)
        }]
    },
    States.INFO: {
        't':
        'Please send me name of your favourite thing',
        'b': [{
            'set foo': (lambda input, data: (States.THANKS, {
                'foo': 'var' + data['foo']
            }))
        }]
    },
    States.FAV: {
        't':
        h.st('Your fav is %s', 'fav'),
        'react':
Esempio n. 5
0
            i.chat.id, "Ближайшая локация '" + places_list[2] +
            "' рядом с вами - " + places_list[3])
        tgf.bot.send_location(i.chat.id, places_list[0], places_list[1])
    return States.WEATHER


class States(Enum):
    START = 1,
    WEATHER = 2


UI = {
    States.START: {
        't':
        'Это бот, который показывает погоду по геопозиции! Выберите нужную точку на карте, чтобы узнать там текущую погоду!',
        "react": h.action(sendLocation, react_to='location')
    },
    States.WEATHER: {
        "react": h.action(sendLocation, react_to='location')
    }
}

tgf.configure(token=telegram_key, state=States.START)
tgf.start(UI)
"""
from tgflow import TgFlow
from enum import Enum
telegram_key='539066078:AAHCUsr8ZoP9JtP5KqOMuL7f_UoFyyH6wik'
class States(Enum):
    START=1
TgFlow.configure(token=telegram_key,
Esempio n. 6
0
UI = {
    States.START: {
        't': 'Hi! You can set up a reminder here.',
        'kb': [
            {
                'Set up a reminder': tgf.action(States.REMIND)
            },
        ]
    },
    States.REMIND: {
        't': 'Please send me a delay in seconds:',
        'b': [{
            'Back': tgf.action(States.START)
        }],
        'react': h.action(handle_delay, react_to='text'),
    },
    States.SET: {
        't': h.st('Delay is %s', 'delay'),
        'b': [
            {
                'back to start': tgf.action(States.START)
            },
        ],
        'clear_trig': 'text',
    },
    States.NOTIF: {
        't': h.st('Hey! time\'s up! delay was: %s', 'delay'),
        'b': [
            {
                'back to start': tgf.action(States.START)
Esempio n. 7
0
    if check:
        return States.LOGGED
    else:
        tgf_obj.bot.send_message(i.chat.id, 'Неверный логин или пароль')
        return States.LOGIN


UI = {
    States.START: {
        't': 'Здравствуйте. Вы уже подключены к нашим услугам?',
        'b': [
            {
                'Да': tgf.action(States.LOGIN)
            },
            {
                'Нет': h.action(States.INFO)
            },
        ],
        'react': h.action(geo, react_to='location'),
    },
    States.INFO: {
        't':
        'Возможно вас заинтересуют наши услуги',
        'b': [
            {
                'Просмотреть': tgf.action(uslugi1)
            },
            {
                'Назад': tgf.action(States.START)
            },
        ]
Esempio n. 8
0
        if '123456' == i.text:
            check = 1
    if check:
        return States.LOGGED
    else:
        tgf_obj.bot.send_message(i.chat.id, 'Неверный логин или пароль')
        return States.LOGIN


UI = {
    States.START: {
        't': 'Добрый день. Вас приветствует система HealthAI',
        'b': [{
            'Войти в систему': tgf.action(States.LOGIN)
        }],
        'react': h.action(qr, react_to='photo'),
    },
    States.LOGGED: {
        't':
        'Личный кабинет',
        'b': [
            {
                'Отсканировать QR': tgf.action(States.QR)
            },
            {
                'Список лекарств': tgf.action(stat, update_msg=False)
            },
            {
                'Отправить фото': tgf.action(States.TAB)
            },
            {