示例#1
0
def message(update, context):
    message_received = update.message.text

    assistant.validate_session(update.effective_chat.id)

    response_text = assistant.send_message(SessionManager.getInstance().getSession(update.effective_chat.id), update.message.text)
    context.bot.send_message(chat_id=update.effective_chat.id, text=response_text)
示例#2
0
def receive_voice(update, context):
    assistant.validate_session(update.effective_chat.id)

    audio_file = BytesIO(update.message.voice.get_file().download_as_bytearray())
    text = voice.convert_voice(audio_file)
    response_text = assistant.send_message(SessionManager.getInstance().getSession(update.effective_chat.id), text)
    context.bot.send_voice(chat_id=update.effective_chat.id, voice=voice.convert_text(response_text))
示例#3
0
 def speak(self):
     recorder.record_to_file("input.wav")
     print("recording finished: input.wav")
     self.user_text = speechtotext.listen("input.wav")
     print("speech to text: " + self.user_text)
     response = assistant.send_message(self.user_text)
     self.assistant_text = str(response[0])
     print("assistant responded: " + self.assistant_text)
     self.respond()
示例#4
0
 def send(self):
     print(self.user_text)
     response = assistant.send_message(self.user_text)
     self.assistant_text = str(response[0])
     self.respond()
示例#5
0
def start(update, context):
    assistant.validate_session(update.effective_chat.id)
    response_text = assistant.send_message(SessionManager.getInstance().getSession(update.effective_chat.id), '')
    context.bot.send_message(chat_id=update.effective_chat.id, text=response_text)