PHP
- 1 ответ
- 0 вопросов
0
Вклад в тег
import cookielib
import urllib
import urllib2
import json
CJ = cookielib.LWPCookieJar()
USER_AGENT = 'LinuxBOT'
OPENER = urllib2.build_opener(urllib2.HTTPCookieProcessor(CJ))
BASE_URL = "https://api.telegram.org/bot<token>/"
url = BASE_URL + 'getUpdates'
req = urllib2.Request(url)
req.add_header("Accept","application/json")
req.add_header('User-agent',USER_AGENT)
content = OPENER.open(req).read()
for result in json.loads(content)['result']:
if(result['message']['text'] == 'привет'):
url = BASE_URL + 'sendMessage'
req = urllib2.Request(url)
req.add_header("Accept","application/json")
req.add_header('User-agent',USER_AGENT)
req.add_data(urllib.urlencode({'chat_id':result['message']['chat']['id'],'text':'Эй Привет чувак!'}))
OPENER.open(req).read()