Online Python Compiler.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''
print("Hello World")
import apiai
import json
import colorama as i
import termcolor as t
from termcolor import colored, cprint
i.init ()
print('----------April----------------')
def send_message(message):
# Токен API к Dialogflow
request = apiai.ApiAI('284b7a7808e148bd8675345de315ba1c').text_request()
# На каком языке будет послан запрос
request.lang = 'ru'
# ID Сессии диалога (нужно, чтобы учить бота)
request.session_id = 'April2020'
# Посылаем запрос к ИИ с сообщением от пользователя
request.query = message
# Разбираем JSON и вытаскиваем ответ
response = json.loads (request.getresponse().read().decode('utf-8'))
a = response['result']['fulfillment']['speech']
print(t.colored(a, 'white', 'on_blue'))
print ('--')
return response['result']['action']
print (t.colored('Напишите мне что-нибудь: ', 'red'))
message = input()
print ('--')
action = None
while True:
action = send_message(message)
if action == 'smalltalk.greetings.bye':
a.break
message = input ()
print ('--')