def other(utterance_metadata, persona, conversation): # TODO somehow implement other... #text = text[0].upper() + text[1:] + "." #utterance_metadata.set_text(text) last_utterance = conversation.last_utterance if last_utterance is None: return eliza_chatbot.respond("") return eliza_chatbot.respond(last_utterance.text)
def random_reply(bot, update): """ send any random replies from eliza """ text = update.message.text reply = eliza_chatbot.respond(text) bot.sendMessage(chat_id=update.message.chat_id, text=reply)
def therapist(msg): content_type, chat_type, chat_id = telepot.glance(msg) text = msg['text'] if text == "/start": bot.sendMessage(chat_id, "Hello, I'm the therapist. How can I help?") else: bot.sendMessage(chat_id, eliza_chatbot.respond(text))
def handle(pesan): global is_chatting global tweet_client chat_id = pesan['chat']['id'] command = pesan['text'] print 'Got command: %s' % command if command == '/timeline' and not is_chatting: bot.sendMessage(chat_id, '\n'.join([message.text for message in tweet_client.handle.home_timeline()])) elif command.split('=')[0] == '/tweet' and not is_chatting: try: tweet_client.hitme(command.split('=')[1] + ' #clara') bot.sendMessage(chat_id, 'twit anda sukses dikirim') except: bot.sendMessage(chat_id, 'ada kesalahan') elif command == '/chat': is_chatting = True bot.sendMessage(chat_id, 'Hi I\'m Clara. Fachrul Razy\'s Personal Assistant. How can I help you?') elif command == '/stopchat': is_chatting = False bot.sendMessage(chat_id, 'See you! long kiss') elif not command.startswith('/') and is_chatting: bot.sendMessage(chat_id, eliza_chatbot.respond(command)) else: pass
def telegram_webhook(): update = request.get_json() if "message" in update: text = update["message"]["text"] chat_id = update["message"]["chat"]["id"] if text == "/start": bot.sendMessage(chat_id, "Hello, I'm Shivam. How can I help you? ") elif text =="Give me a compliment": bot.sendMessage(chat_id, "You look really good from far away!!") #bot.sendMessage(chat_id, emojize(":smile:", use_aliases=True)) elif text =="I am your creator": bot.sendMessage(chat_id, "Does that give you power over me !!") elif text =="Do you know siri?": bot.sendMessage(chat_id, "No i am not interested in knowing her , cortana is good :)") elif text =="What time is it?": bot.sendMessage(chat_id, "check ur phone, or watch .") elif text =="Emergency contacts": bot.sendMessage(chat_id, "Dad - XXXXXXXX" + " " + "Mom - xxxxxxxxxxxx") elif text =="Who created you?": bot.sendMessage(chat_id, "Shivam Ahirao") elif text =="Who coded you?": bot.sendMessage(chat_id, "Shivam Ahirao") elif text =="who is your brother?": elif text =="SPPU timetable": bot.sendMessage(chat_id, "plz click on the link ->" + "http://collegecirculars.unipune.ac.in/sites/examdocs/Examiantions%20Timetables/Forms/AllItems.aspx") elif text =="SPPU Results": bot.sendMessage(chat_id, "plz click on the link ->" + "http://www.unipune.ac.in/university_files/results.htm") elif text =="Who are you?": bot.sendMessage(chat_id, "hello I am a ChatBot for Mr. Shivam Ahirao") elif text =="What is your name?": bot.sendMessage(chat_id, "hello I am Bot and my name is InsaneShivam101 , nice to meet you") elif text =="Where do you live?": bot.sendMessage(chat_id, "I live in ur phone") elif text =="How can i reach to shivam?": bot.sendMessage(chat_id, "pls click on the link ->" + "https://www.facebook.com/shivam.ahirao") elif text =="How old are you?": bot.sendMessage(chat_id, "Bot's never tell their age ;)") elif text =="which languages do you speak?": bot.sendMessage(chat_id, "I can speak English.") elif text =="How are you?": bot.sendMessage(chat_id, "I am good!") elif text =="Open Facebook": bot.sendMessage(chat_id, "pls click on the link ->" + "https://www.facebook.com/") elif text =="Open fb": bot.sendMessage(chat_id, "pls click on the link ->" + "https://www.facebook.com/") elif text =="Open Google": bot.sendMessage(chat_id, "pls click on the link ->" + "https://www.google.com/") elif text =="Open LinkedIn": bot.sendMessage(chat_id, "Pls click on the link ->" + "https://www.linkedin.com/") elif text =="Open YouTube": bot.sendMessage(chat_id, "Pls click on the link ->" + "https://www.youtube.com/") else: bot.sendMessage(chat_id, eliza_chatbot.respond(text)) return "OK"
def whoIs(query, sessionID="general"): try: return wikipedia.summary(query) except: for newquery in wikipedia.search(query): try: return wikipedia.summary(newquery) except: pass return eliza_chatbot.respond(query)
async def hande(msg): content_type, chat_type, chat_id = telepot.glance(msg) command = msg['text'] print(content_type, chat_type, chat_id) print('Got command: %s' % command) if content_type == 'text': if command == "/start": await bot.sendMessage(chat_id, "Hello, do you need any help?") else: await bot.sendMessage(chat_id, eliza_chatbot.respond(command))
async def on_message(message): # Command Handler - tm of endendragon if len(message.content.split() ) > 0: #making sure there is actually stuff in the message msg_cmd = message.content.split()[0].lower( ) # get first word im message if msg_cmd[0] == config["COMMAND_PREFIX"]: # test for cmd prefix msg_cmd = msg_cmd[1:] # remove the command prefix cmd = getattr(Command, msg_cmd, None) #check if cmd exist, if not its none if cmd: # if cmd is not none... await client.send_typing(message.channel) #this looks nice await getattr(Command, msg_cmd)(message ) #actually run cmd, passing in msg obj elif msg_cmd == "<@{}>".format( client.user.id): #make sure it is a mention (eliza handler) await client.send_typing(message.channel) user_query = message.content.split(" ", 1)[1] response = eliza_chatbot.respond(user_query) await client.send_message( message.channel, "{}, {}".format(message.author.mention, response))
def get_response(user_response): global sent_tokens robo_response = '' sent_tokens.append(user_response) TfidfVec = TfidfVectorizer(tokenizer=LemNormalize, stop_words='english') tfidf = TfidfVec.fit_transform(sent_tokens) vals = cosine_similarity(tfidf[-1], tfidf) idx = vals.argsort()[0][-2] flat = vals.flatten() flat.sort() req_tfidf = flat[-2] if (req_tfidf == 0): if (user_response[:6] == 'who is' or user_response[:7] == 'what is' or user_response[:7] == 'tell me'): question = user_response[5:] robo_response = whoIs(question) return robo_response #robo_response = robo_response + "I am sorry! I don't understand you" robo_response = robo_response + eliza_chatbot.respond(user_response) return robo_response else: robo_response = robo_response + sent_tokens[idx] return robo_response
def psychiatrist(utterance, responder_id): """ Use ELIZA to generate response utterances when the topic is on user. """ return Utterance(responder_id, DA.other, "self_user", 5, 5, eliza_chatbot.respond(utterance.text))