def test_text_message_with_replies(self):
     chat_id = '0'
     adapter = TelegramAdapter(chat_id)
     message = TextMessage(text='Hello world!')
     message.add_quick_reply(QuickReply(title='A'))
     message.add_quick_reply(QuickReply(title='B'))
     print(adapter.to_response(message))
 def test_chat_id(self):
     adapter = TelegramAdapter(1099511627776)
     self.failUnless(adapter.id == 1099511627776)
     adapter = TelegramAdapter('1099511627776')
     self.failUnless(adapter.id == 1099511627776)
     try:
         adapter = TelegramAdapter('foo')
         self.fail()
     except:
         pass
 def test_text_message_with_buttons(self):
     chat_id = '0'
     adapter = TelegramAdapter(chat_id)
     message = TextMessage(text='Hello world!')
     message.add_button(LinkButton(title='A', url='http://example.com'))
     message.add_button(
         PayloadButton(title='B',
                       payload={
                           '_state': 'default.root:accept',
                           'item_id': 'e_12345_67890'
                       }))
     print(adapter.to_response(message))
 def test_list_template_message(self):
     chat_id = '0'
     adapter = TelegramAdapter(chat_id)
     message = ListTemplate()
     for i in range(3):
         url = 'http://placehold.it/300x200'
         element = GenericTemplateElement(
             title='foo',
             subtitle='lorem ipsum dolor sit amet.',
             image_url=url)
         message.add_element(element)
     response = adapter.to_response(message)
     print(response)
Beispiel #5
0
 def post_message(uid, chat_id, response):
     from golem.core.interfaces.adapter.telegram import TelegramAdapter
     base_url = TelegramInterface.get_base_url()
     if not base_url:
         return
     adapter = TelegramAdapter(chat_id)
     messages = adapter.to_response(response)
     for method, payload in messages:
         url = base_url + method
         response = requests.post(url, data=payload)
         if not response.json()['ok']:
             logging.error('Telegram request failed!')
             logging.error(response.json())
             logging.error('for method {}'.format(method))
             logging.error('message is:')
             logging.error(payload)
             return
 def test_unknown_message(self):
     chat_id = '0'
     adapter = TelegramAdapter(chat_id)
     print(adapter.to_response('<?php alert("WASSUP"); ?>'))
 def test_text_message(self):
     chat_id = '0'
     adapter = TelegramAdapter(chat_id)
     message = TextMessage(text='Hello world!')
     print(adapter.to_response(message))