def handle_postback(raw_event): bot = Bot(utils.config["page_access_token"]) cuser = messages.user(bot.get_user_info(raw_event["sender"]["id"]), raw_event["sender"]["id"]) payload = raw_event["postback"]["payload"] red_user = utils.get_redis(cuser.id) # welcome message, user has not signed up yet if red_user == None: messages.intro_message(bot, cuser) return # if something is different between the user and the database user if red_user.is_different(cuser): utils.set_redis(cuser.id, red_user) if payload == "starting_gate": # and not red_user.looking_for_chat: if not red_user.in_chat and not red_user.looking_for_chat: red_user.set_looking_for_chat() found_chat = red_user.search_for_chat() bot.send_text_message(red_user.id, "Searching...") if found_chat: messages.found_chat_reply(bot, red_user, found_chat) elif red_user.looking_for_chat: messages.send_in_limbo(bot, red_user) elif payload == "decision_time_yes" or payload == "decision_time_no": if not red_user.on_edge: return other_user = utils.get_redis(red_user.in_chat_with) if payload == "decision_time_no": messages.decision_time_no(bot, red_user, other_user) else: if red_user.showed_id: messages.waiting_for_decision(bot, red_user) return messages.decision_time_yes(bot, red_user, other_user) elif payload == "start_message": handle_message(raw_event)
def handle_message(raw_event): # use pymessenger to make an API call to FB to get the # info about the user who send the message bot = Bot(utils.config["page_access_token"]) user_id = raw_event["sender"]["id"] user_info = bot.get_user_info(user_id) cuser = messages.user(user_info, user_id) red_user = utils.get_redis(cuser.id) # welcome message, user has not signed up yet if red_user == None: messages.intro_message(bot, cuser) return # if something is different between the user and the database user if red_user.is_different(cuser): utils.set_redis(cuser.id, red_user) elif red_user.looking_for_chat: messages.send_in_limbo(bot, red_user) elif red_user.in_chat: if "message" in raw_event.keys(): raw_message = raw_event["message"] messages.handle_chat(bot, red_user, raw_message) else: bot.send_text_message(user_id, "You are in a chat currently") elif red_user.on_edge and not red_user.showed_id: messages.send_decision_message(bot, red_user) elif red_user.on_edge and red_user.showed_id: messages.waiting_for_decision(bot, red_user) elif not red_user.in_chat and not red_user.looking_for_chat and not red_user.on_edge: messages.send_starting_gate(bot, red_user)
def question_view(request): ans = intro_message() if request.method == 'POST': form = FriggForm(request.POST) if form.is_valid(): quest = request.POST['question'] ans = answer(quest) context={"form": form, "subtest": ans} return render(request, "FriggTemplates/index.html", context) return HttpResponse("/FriggResponse/") #acontece de qualquer forma... form = FriggForm() context={"form": form, "intro": ans} return render_to_response("FriggTemplates/index.html", context ,RequestContext(request), RequestContext(request))
def question_view(request): feed = FeedbackForm() ans = intro_message() form = FriggForm() context={"form": form, "intro": ans, "feedback": feed} return render_to_response("FriggTemplates/index.html", context ,RequestContext(request), RequestContext(request))