2015-06-26 09:56:25 +03:00
|
|
|
# pyTelegramBotAPI
|
|
|
|
Python Telegram bot api.
|
2015-06-26 09:58:20 +03:00
|
|
|
|
|
|
|
## Example
|
|
|
|
|
2015-06-26 13:05:23 +03:00
|
|
|
* Send Message
|
|
|
|
|
2015-06-26 09:58:20 +03:00
|
|
|
```python
|
|
|
|
import telebot
|
|
|
|
|
|
|
|
TOKEN = '<token string>'
|
|
|
|
|
|
|
|
tb = telebot.TeleBot(TOKEN)
|
|
|
|
# tb.send_message(chatid,message)
|
|
|
|
print tb.send_message(281281, 'gogo power ranger')
|
|
|
|
```
|
2015-06-26 13:05:23 +03:00
|
|
|
|
|
|
|
* Echo Bot
|
|
|
|
|
|
|
|
```python
|
2015-06-26 13:11:11 +03:00
|
|
|
import telebot
|
2015-06-26 13:05:23 +03:00
|
|
|
import time
|
|
|
|
|
2015-06-26 13:11:11 +03:00
|
|
|
TOKEN = '<token_string>'
|
2015-06-26 13:05:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
def listener(*messages):
|
2015-06-26 13:11:11 +03:00
|
|
|
"""
|
|
|
|
When new message get will call this function.
|
|
|
|
:param messages:
|
|
|
|
:return:
|
|
|
|
"""
|
2015-06-26 13:05:23 +03:00
|
|
|
for m in messages:
|
|
|
|
chatid = m.chat.id
|
|
|
|
text = m.text
|
|
|
|
tb.send_message(chatid, text)
|
|
|
|
|
|
|
|
|
|
|
|
tb = telebot.TeleBot(TOKEN)
|
|
|
|
tb.get_update() # cache exist message
|
2015-06-26 13:11:11 +03:00
|
|
|
tb.set_update_listener(listener) #register listener
|
2015-06-26 13:05:23 +03:00
|
|
|
tb.polling(3)
|
|
|
|
while True:
|
|
|
|
time.sleep(20)
|
|
|
|
```
|