def handle_image(sender, url): try: partner = activechatsdb.get_partner(sender) alias = activechatsdb.get_alias(sender) message = TextTemplate(text=alias + " has sent you an image.") send_message(message.get_message(), id=partner) message = AttachmentTemplate(url=url, type='image') send_message(message.get_message(), id=partner) #dummy1 except Exception as e: print("IMAGE ERROR", str(e))
def restart_bot(id): show_typing(id=id, duration=1) print("here") if activechatsdb.isActive(id): print("ACTIVE", id) partner = activechatsdb.get_partner(id) activechatsdb.delete_chat_entries(id) message = TextTemplate(text="Your active chat has been ended.") send_message(message=message.get_message(), id=id) message = TextTemplate( text="Your active chat has been ended from the other side.") send_message(message=message.get_message(), id=partner) show_typing(id=partner, duration=1) send_newchat_prompt(id=partner) if waitlistdb.isWaiting(id): waitlistdb.delist(id) message = TextTemplate(text="You have been removed from the waitlist") send_message(message=message.get_message(), id=id) show_typing(id=id, duration=1) send_newchat_prompt(id=id)
def endChat(sender): try: partner = activechatsdb.get_partner(sender) alias1 = activechatsdb.get_alias(sender) alias2 = activechatsdb.get_alias(partner) except: message = TextTemplate( text="No open chat was found which can be closed") send_message(message.get_message(), id=sender) show_typing(id=sender, duration=2) send_newchat_prompt(id=sender) return imurl = APP_URL + "static/endchat1.jpg/" # -------------------------- SENDER --------------------------- # replies_sender = [{ "title": "Share profile", "payload": json.dumps({ "keyword": "profile_share", "ans": "y", "alias": alias1, "partner": partner }) }, { "title": "Don't share", "payload": json.dumps({ "keyword": "profile_share", "ans": "n", "alias": alias1, "partner": partner }) }] message = GenericTemplate() title = "You have ended the chat with " + alias2 subtitle = "Hope you had a nice experience." message.add_element(title=title, subtitle=subtitle, image_url=imurl) send_message(message=message.get_message(), id=sender) message = TextTemplate(text="Would you like to share your profile with " + alias2 + "?").get_message() message = add_quick_reply(message, title=replies_sender[0]["title"], payload=replies_sender[0]["payload"]) message = add_quick_reply(message, title=replies_sender[1]["title"], payload=replies_sender[1]["payload"]) send_message(message=message, id=sender) # ----------------------------------------------------------------------- # # ------------------------------- PARTNER ------------------------------- # replies_partner = [{ "title": "Share profile", "payload": json.dumps({ "keyword": "profile_share", "ans": "y", "alias": alias2, "partner": sender }) }, { "title": "Don't share", "payload": json.dumps({ "keyword": "profile_share", "ans": "n", "alias": alias2, "partner": sender }) }] message = GenericTemplate() title = alias1 + " has quit the chat" subtitle = "Hope you had a nice experience while it lasted." message.add_element(title=title, subtitle=subtitle, image_url=imurl) send_message(message=message.get_message(), id=partner, pause_check=True) message = TextTemplate(text="Would you like to share your profile with " + alias1 + "?").get_message() message = add_quick_reply(message, title=replies_partner[0]["title"], payload=replies_partner[0]["payload"]) message = add_quick_reply(message, title=replies_partner[1]["title"], payload=replies_partner[1]["payload"]) send_message(message=message, id=partner, pause_check=True) # --------------------------------------------------------------- # try: activechatsdb.delete_chat_entries(user=sender) except Exception, e: print("ENDCHAT ERROR", str(e))