def received_postback(event): sender_id = event.sender_id recipient_id = event.recipient_id time_of_postback = event.timestamp payload = event.payload page.typing_on(sender_id) page.send( sender_id, "Welcome! Search yelp for something like this:\nDISH, LOCATION\n\nChange default location with location=LOCATION" ) db.insert_user(sender_id) page.typing_off(sender_id)
def main(): try: client.run(TOKEN) finally: if not db.user_exists(p_id): db.insert_user(p_id, get_p()) else: last_seen = get_p() if last_seen: db.change_timestamp(p_id, get_p()) else: print(p_seen) for key in p_seen.keys(): if p_seen[key]: db.change_timestamp(p_id, p_seen[key]) break
def users_POST(**kwargs): user = auth.authenticate() if not user.can_create_users(): abort(403) if request.content_type != 'application/json': abort(415, utility.ERR_FMTS['BAD_MIME'] % 'application/json') db_write = {} db_write['name'] = request.json.get('name') db_write['mail'] = request.json.get('mail') db_write['login'] = request.json.get('login') db_write['password'] = request.json.get('password') db_write['type'] = request.json.get('type') dbhandler.insert_user(db_write) return Response()
def message_handler(event): sender_id = event.sender_id message = event.message.get('text') state = db.get_state(sender_id) if not message: return # if message == admin_key: # # if db.insert_admin(sender_id): # page.send(sender_id, "Added you as an admin") # else: # page.send(sender_id, "Already an Admin") if not (message == password) and not (db.user_exists(sender_id)): handle_unsub(sender_id) return elif message == password and db.insert_user(sender_id): page.send(sender_id, "Subbed to all products") if (state == 0): if (message.lower() == "unsubscribe"): db.delete_user(sender_id) page.send(sender_id, "Unsubbed, you may now delete the conversation") elif (state == 1): message = re.sub("[\W+]", "_", message.upper()) deleted = db.delete_sub(sender_id, message) if (deleted): page.send(sender_id, "Deleted your item") else: page.send( sender_id, "Item not found (product name not exact or you are already unsubscribed to this product)" ) db.change_state(sender_id, 0) return "Message processed"
def callback_clicked_yes_r(payload, event): sender_id = event.sender_id db.insert_user(sender_id) page.send(sender_id, "Subbed to all products")