def getUsersFeatures(chat_id): keyboard = [["get cheapest basket"], ["get sub baskets"]] x = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) requests.get( "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&reply_markup={}" .format(TOKEN, chat_id, "choose your preference for your shopping list", x.to_json()))
def add_product_checkout(chat_id): keyboard = [["add product"], ['remove product from basket'], ["check out"]] x = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) requests.get( "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&reply_markup={}&disable_commands=True" .format(TOKEN, chat_id, "please choose the action for your basket", x.to_json()))
def getStart(chat_id): keyboard = [["create basket"], ["get most recent basket"]] x = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) requests.get( "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&reply_markup={}" .format(TOKEN, chat_id, "So, what would you like to choose?", x.to_json()))
def getPreviousBasketFeatures(chat_id): keyboard = [["add more items"], ["checkout on the same basket"], ['remove product from basket']] x = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) requests.get( "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&reply_markup={}" .format(TOKEN, chat_id, "What would you like to do next ?", x.to_json()))
def add_botton(chatid, custom_keyboard, title): try: print("chatid") print(chatid) reply_markup = ReplyKeyboardMarkup(custom_keyboard) res = requests.get( TELEGRAM_SEND_BOTTON_URL.format(chatid, title, reply_markup.to_json())) except: print("exception provoked from connect_to_bot.add_gender_botton")
def message(user_message): try: general_teams_list = [ sub['team_name'] for sub in Matches_model.get_teams() ] messageL = user_message['text'].split() print(messageL) command = messageL[0] user_id = user_message['chat']['id'] print(user_id) if user_message['text'].lower() == "menu": x = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) requests.get( "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&reply_markup={}" .format(TOKEN, user_id, "What do you like to do\U00002753", x.to_json())) if command.lower().startswith("hi") or command == "/start": parse(TOKEN, user_message, start_msg) elif user_message['text'].lower() == "list today matches": list_of_matches = Matches_model.get_today_matches() parse(TOKEN, user_message, match_show(list_of_matches)) elif user_message['text'].lower() == "list all teams": list_of_teams = Matches_model.get_teams() parse(TOKEN, user_message, teams_show(list_of_teams)) elif user_message['text'].lower() == "add to favorite": fav_teams = [[item["team_name"]] for item in Matches_model.get_teams()] x = ReplyKeyboardMarkup(fav_teams, one_time_keyboard=True, resize_keyboard=True) requests.get( "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&reply_markup={}" .format(TOKEN, user_id, "please choose your selection", x.to_json())) elif user_message['text'] in general_teams_list: Matches_model.add_to_favorite(user_id, user_message['text']) parse(TOKEN, user_message, "favorite list updated") elif command == "remove_from_favorite": Matches_model.remove_from_favorite(user_id, messageL[1:]) parse(TOKEN, user_message, "favorite list updated") elif user_message['text'].lower() == "my favorite teams": result = "\n".join(Matches_model.get_user_favorite(user_id)) parse(TOKEN, user_message, "Here are your current favorite teams: \n" + result) elif user_message['text'].lower() == "subscribe for match": listOfMatches = [[ str(item['match_id']) + " " + item["home_team"] + " VS " + item["visitor_team"] ] for item in Matches_model.get_today_matches()] x = ReplyKeyboardMarkup(listOfMatches, one_time_keyboard=True, resize_keyboard=True) requests.get( "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&reply_markup={}" .format(TOKEN, user_id, "subscribe to match", x.to_json())) elif command == "Unsubscribe": matches = Matches_model.get_user_matches(user_id) listOfMatches = [[ str(item['match_id']) + " " + item["home_team"] + " Vs " + item["visitor_team"] ] for item in matches] x = ReplyKeyboardMarkup(listOfMatches, one_time_keyboard=True, resize_keyboard=True) requests.get( "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&reply_markup={}" .format(TOKEN, user_id, "Unsubscribe to match", x.to_json())) elif user_message['text'].lower() == "subscribe future matches": x = ReplyKeyboardMarkup(this_week, one_time_keyboard=True, resize_keyboard=True) requests.get( "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&reply_markup={}" .format(TOKEN, user_id, "Unsubscribe to match", x.to_json())) elif len(command.split("-")) == 3: API_model.get_today_games(command) listOfMatches = [[ str(item['match_id']) + " " + item["home_team"] + " VS " + item["visitor_team"] ] for item in Matches_model.get_today_matches(command)] x = ReplyKeyboardMarkup(listOfMatches, one_time_keyboard=True, resize_keyboard=True) requests.get( "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&reply_markup={}" .format(TOKEN, user_id, "subscribe to match", x.to_json())) elif command.lower().startswith("help"): parse(TOKEN, user_message, help) elif "VS" in messageL: parse(TOKEN, user_message, subscribe_msg(messageL[0])) Matches_model.add_match_subscription(messageL[0], user_id) elif "Vs" in messageL: Matches_model.remove_match_subscription(messageL[0], user_id) parse(TOKEN, user_message, unsubscribe_msg(messageL[0])) except: pass