def message(): """ Handle incoming messages, passed as HTTP requests via the vumi HTTP API. """ logger.debug("MESSAGE endpoint called") try: tmp = request.get_json() msg = VumiMessage(tmp) if hasattr(msg, 'content') and msg.content == "state: wait_ussrc": logger.debug("End of session message received.") else: logger.debug(msg.msg_type + " message received.") if msg.msg_type == "ussd": user_id = msg.from_addr # user's cellphone number content = msg.content # selected menu item, if any mark_online(user_id) selected_item = None try: selected_item = int(content) except (ValueError, TypeError): pass logger.debug(selected_item) reply_content = generate_output(user_id, selected_item) if "Your number has been added to the list." in reply_content: update_notification_list(msg.from_addr, "add") msg.send_reply(reply_content) elif msg.msg_type == "sms": msg.save_query() tmp = "Thank you for submitting your query. It will be attended to as soon as possible." msg.send_reply(tmp) else: logger.error("Incorrect message type encountered.") except Exception as e: logger.exception(e) raise return make_response("OK")