app = Flask(__name__)
@app.route('/my_bot', methods=['POST'])
def bot():
data = TheRequest.get_json(force=True, silent=True)
if not data or 'type' not in data:
return 'not ok'
if data['type'] == 'confirmation':
return 'confirm'
elif data['type'] == 'message_new':
text = data['object']['text']
text = text.strip()
request = apiai.ApiAI(
'token').text_request()
request.lang = 'ru' #
request.session_id = 'Bot'
request.query = text
responseJson = json.loads(request.getresponse().read().decode('utf-8'))
response = responseJson['result']['fulfillment']['speech']
if response:
vk.messages.send(random_id=time.time(), peer_id=data['object']['peer_id'], message=response)
else:
vk.messages.send(random_id=time.time(), peer_id=data['object']['peer_id'], message='не понял')
return 'ок'
return 'ок'
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000)))