Пример #1
0
                                                  '_': lambda msg: True
                                              }])
        self._count = 0

    def on_message(self, msg):
        self._count += 1
        flavor = telepot.flavor(msg)

        print '%s %d: %d: %s: %s' % (type(self).__name__, self.id, self._count,
                                     flavor, telepot.glance(msg,
                                                            flavor=flavor))


# Do some simple stuff for every message, to be paired with per_message()
def simple_function(seed_tuple):
    bot, msg, id = seed_tuple
    print 'Simply print:', msg


TOKEN = sys.argv[1]

bot = telepot.DelegatorBot(TOKEN, [
    (per_chat_id(), create_open(ChatHandlerSubclass, timeout=10)),
    (per_from_id(), create_open(UserHandlerSubclass, timeout=20)),
    (per_inline_from_id(),
     create_open(UserHandlerSubclassInlineOnly, timeout=10)),
    (per_application(), create_open(OnlyOneInstance)),
    (per_message(), call(simple_function)),
])
bot.message_loop(run_forever=True)
Пример #2
0
    def __init__(self, seed_tuple):
        super(OneInstanceOnly, self).__init__(seed_tuple, capture=[{'_': lambda msg: True}])
        self._count = 0

    def on_message(self, msg):
        self._count += 1
        flavor = telepot.flavor(msg)

        print '%s %d: %d: %s: %s' % (type(self).__name__, self.id, self._count, flavor, telepot.glance(msg, flavor=flavor))

# Do some simple stuff for every message, to be paired with per_message()
def simple_function(seed_tuple):
    bot, msg, id = seed_tuple
    print 'Simply print:', msg


TOKEN = sys.argv[1]

bot = telepot.DelegatorBot(TOKEN, [
    (per_chat_id(), create_open(ChatHandlerSubclass, timeout=10)),

    (per_from_id(), create_open(UserHandlerSubclass, timeout=20)),

    (per_inline_from_id(), create_open(InlineUserHandlerSubclass, timeout=10)),

    (per_application(), create_open(OneInstanceOnly)),

    (per_message(), call(simple_function)),
])
bot.message_loop(run_forever=True)
Пример #3
0
                        need_phone_number=True,
                        reply_markup=kb.custom_inline(price))
                    print(sent)
                    bot.sendMessage(chat_id,
                                    parse_mode='HTML',
                                    text='<b>Add to cart instead?</b>\n'
                                    'Click: /add_{}'.format(name_to_compare))
                    break

            else:
                bot.sendMessage(chat_id,
                                reply_markup=kb.default_keyboard,
                                text='Sorry, there seems to be an error!\n'
                                'Try out some of the actions below?')


bot = telepot.DelegatorBot(
    Token.TOKEN, [(per_message(flavors=['chat']), call(send_invoice)),
                  pave_event_space()(
                      per_invoice_payload(),
                      create_open,
                      OrderProcessor,
                      timeout=30,
                  )])

print('Listening...')
MessageLoop(bot).run_as_thread()

while 1:
    time.sleep(10)
Пример #4
0
    if content_type == 'text':
        sent = bot.sendInvoice(
                   chat_id, "Nick's Hand Cream", "Keep a man's hand like a woman's",
                   payload='a-string-identifying-related-payment-messages-tuvwxyz',
                   provider_token=PAYMENT_PROVIDER_TOKEN,
                   start_parameter='abc',
                   currency='HKD', prices=[
                       LabeledPrice(label='One Case', amount=987),
                       LabeledPrice(label='Package', amount=12)],
                   need_shipping_address=True, is_flexible=True)  # required for shipping query

        print('Invoice sent:')
        pprint(sent)


TOKEN = sys.argv[1]
PAYMENT_PROVIDER_TOKEN = sys.argv[2]

bot = telepot.DelegatorBot(TOKEN, [
    (per_message(flavors=['chat']), call(send_invoice)),
    pave_event_space()(
        per_invoice_payload(), create_open, OrderProcessor, timeout=30,
    )
])

MessageLoop(bot).run_as_thread()

while 1:
    time.sleep(10)