def _render_configuration_page(): model = {} message = ( "Dictionary integration has been installed successfully in this room. Type /meaning <word>" + "to get the meaning of the word." ) tasks.send_notification(tenant.id, message, tenant.room_id, color="green") return render_template("configure.html", **model)
def _handle_dict_callback(): """This function acts as a HipChat webhook and responds whenever it encounters the appropriate slash command. """ data = json.loads(request.data) room_id = data["item"]["room"]["id"] tenant_id = data["oauth_client_id"] input_message = data["item"]["message"]["message"] if len(input_message.split(" ")) > 2: message = "Please enter single word to know its meaning." elif len(input_message.split(" ")) == 1: message = "Usage: /dict <<word>>. It will return you the meaning of the word." else: word = input_message.split(" ")[1] meaning = dictionary.meaning(word) synonym = dictionary.synonym(word) antonym = dictionary.antonym(word) message = "Sorry, We are unable to find meaning of the word <b>'" + word + "'</b>. Please try some other word." if meaning: meaning = construct_meaning(meaning) if synonym: synonym = ", ".join(synonym) if antonym: antonym = ", ".join(antonym) message = create_html_from_meaning_list(word, meaning, synonym, antonym) try: tasks.send_notification(tenant_id, message, room_id, color="random") except InvalidCredentials as ex: app.logger.error(ex) return "Invalid Credentials", 401 except BadRequest as ex: app.logger.error(ex) return "Bad Request", 400 except InternalServerError as ex: app.logger.error(ex) return "Internal Server Error", 500 except Exception as ex: app.logger.error(ex) return "Success", 200