def sendasync_controller(data): if 'USER' in data and 'MSG' in data: try: return telegram_api.send_message(data['USER'], data['MSG']) except Exception as e: logging.error(e) return {'error': 'error while sending msg : controller'} else: return { 'error': 'USER and MSG params should be present in the POST body' }
def process_message(request): oMessage = telegram.Message(request) message = oMessage.message #prints if debug is toggled on if DEBUG_TOGGLE: print(message) if "text" in message: messageSplit = (message["text"]).split(' ', 1) command = (messageSplit[0]).split('@', 1) if command[0] in textCommandsList: (textCommandsList[command[0]])(oMessage) elif oMessage.get_chat_id() in blacklisted: param = {"chat_id": main_group_id, "text": oMessage.get_message_text()} telegram.send_message(param) elif "photo" in message: if "caption" in message: captionSplit = (message["caption"]).split(' ', 1) command = (captionSplit[0]).split('@', 1) if command[0] in photoCommandsList: (photoCommandsList[command[0]])(oMessage) elif oMessage.get_chat_id() in blacklisted: param = {"chat_id": main_group_id, "caption": oMessage.get_message_caption(), "photo": oMessage.get_message_photo()} telegram.send_photo(param) elif "animation" in message: send_anon_gif(oMessage) elif "video" in message: if "caption" in message: captionSplit = (message["caption"]).split(' ',1) command = (captionSplit[0]).split('@',1) if command[0] in videoCommandsList: (videoCommandsList[command[0]])(oMessage) elif "sticker" in message: send_anon_sticker(oMessage) elif "document" in message: send_anon_document(oMessage) return Response(status=200)
def feat_help(oMessage): message_split = oMessage.get_message_text().split(' ', 1) help_message = "" group_id = oMessage.get_chat_id() language = database_handler.get_group_language(group_id) if len(message_split) <= 1: help_message = "help" else: help_message = message_split[1] param = {"chat_id": group_id, "text": str_data.get_string([language, "help", help_message]), "parse_mode": "HTML"} return telegram.send_message(param)
def finish_spotted(index = 0): finishedSpottedMessage = SPOTTED_LIST[0] text = "Votação encerrada! Resultados:\n" mostVoted = "" for key in finishedSpottedMessage["voting"]["votes"]: if key.isnumeric(): text = text + '<a href="tg://user?id=' + key + '">Essa pessoa sem username</a>: ' else: text = text + "@" + key + ": " votes = finishedSpottedMessage["voting"]["votes"][key] text = text + str(votes) + "\n" if mostVoted not in finishedSpottedMessage["voting"]["votes"] or votes > finishedSpottedMessage["voting"]["votes"][mostVoted]: mostVoted = key text = text + "Votos totais: " + str(finishedSpottedMessage["voting"]["amount"]) + "\n" if (mostVoted == finishedSpottedMessage["username"] and mostVoted != "") or mostVoted == str(finishedSpottedMessage["user_id"]): text = text + "Parabéns! Vocês acertaram. O usuário que enviou foi " if finishedSpottedMessage["username"] == "": text = text + '<a href="tg://user?id=' + mostVoted + '">' + finishedSpottedMessage["first_name"] + '.</a>!' else: text = text + "@" + finishedSpottedMessage["username"] + "!" else: text = text + "A pessoa mais votada foi " if mostVoted.isnumeric(): text = text + '<a href="tg://user?id=' + mostVoted + '">essa pessoa sem username.</a>' else: text = text + "@" + mostVoted text = text + ". Mas ela não enviou o spotted. A pessoa que enviou continua anônima :(" chatId = finishedSpottedMessage["chat_id"] parseMode = "HTML" replyId = finishedSpottedMessage["message_id"] param = {"text": text, "chat_id": chatId, "parse_mode": parseMode, "reply_to_message_id": replyId} if mostVoted != "": telegram.send_message(param) SPOTTED_LIST.pop(0)
def send_anon_text(oMessage, startingText = "<b>Mensagem anônima</b>: "): group_id = database_handler.get_registered_user(oMessage.get_sender_id()) if group_id != None: messageSplit = oMessage.get_message_text().split(' ', 1) if len(messageSplit) > 1: param = {"chat_id": group_id, "text": startingText + messageSplit[1], "parse_mode": "HTML"} return telegram.send_message(param) else: return {} else: oMessage.reply("Você ainda não está registrado. Use /register para se registrar.") return {}
def lambda_handler(event, context): """ payload like: { "deal_text": "str", "deal_url": "str" } """ # error = False # try: payload = json.loads(event['body']) deal_text = payload['title'] deal_url = payload['deal_url'] for user in storage_user.get_active_user_list(): for kw in user['sub_list']: if kw == '': continue if kw in deal_text: telegram_api.send_message( f'Deal Alert: {deal_text} Source:<a href="{deal_url}">Dealmoon</a>', user['user_id'], parse_mode='HTML') break # except Exception as e: # error_text = str(e) # return { # 'statusCode': -1, # 'body': { # 'error': str(e), # 'timestamp': time.time() # } # } # else: return {'statusCode': 200, 'body': {'timestamp': time.time()}}
conversations_path = settings['conversations_path'] wikidata_dump_path = settings['wikidata_dump_path'] save_cache = settings['save_cache'] identifier_predicates_path = settings['identifier_predicates_path'] telegram_chat_id = settings['telegram_chat_id'] telegram_active = isinstance(telegram_chat_id, int) # open the identifier predicates with open(identifier_predicates_path, "r") as data: identifier_predicates = json.load(data) if __name__ == '__main__': start_time = time.time() if telegram_active: telegram.send_message( "Starting benchmarking: " + str( (domain, number_of_frontier_nodes, hyperparameters, conversations_path, wikidata_dump_path)), telegram_chat_id) # open the conversations with open(conversations_path, "r") as data: conversations = json.load(data) question_counter = 0 total_mrr_score = 0.0 total_precision_at_1_score = 0.0 total_hit_at_5_score = 0.0 for conversation in conversations: if domain != "ALL" and (not conversation['domain'] == domain): continue questions = [turn['question'] for turn in conversation['questions']]
for conversation in conversations: if domain != "ALL" and (not conversation['domain'] == domain): continue questions = [turn['question'] for turn in conversation['questions']] answers = answer_conversation(questions, tagmeToken, hyperparameters, number_of_frontier_nodes) golden_answers = [string.parse_answers(turn['answer']) for turn in conversation['questions']] for index, answer in enumerate(answers[1:]): total_mrr_score += MRR_score(answer, golden_answers[1:][index]) total_precision_at_1_score += precision_at_1(answer, golden_answers[1:][index]) total_hit_at_5_score += hit_at_5(answer, golden_answers[1:][index]) question_counter += 1 print_results("Test") print_results( domain ) print_results( "MRR_score: " + str((question_counter, (total_mrr_score/float(question_counter)), total_mrr_score))) print_results( "P@1: " + str((question_counter, (total_precision_at_1_score/float(question_counter)), total_precision_at_1_score))) print_results( "H@5: " + str((question_counter, (total_hit_at_5_score/float(question_counter)), total_hit_at_5_score))) print_results("\n") wd.save_cached_data() spacy.save_cached_data() if telegram_active: telegram.send_message("MRR_score: " + str((question_counter, (total_mrr_score/float(question_counter)), total_mrr_score)), telegram_chat_id) telegram.send_message("P@1: " + str((question_counter, (total_precision_at_1_score/float(question_counter)), total_precision_at_1_score)), telegram_chat_id) telegram.send_message("H@5: " + str((question_counter, (total_hit_at_5_score/float(question_counter)), total_hit_at_5_score)), telegram_chat_id)
def lambda_handler(event, context): """ Lambda entrance """ try: message = json.loads(event['body']) chat_id = message['message']['chat']['id'] msg_text = message['message']['text'].strip() error, cmd, text = parse_command(msg_text) if error: telegram_api.send_message(HELP_TEXT, chat_id) return {'statusCode': 200, 'body': 'parse cmd error'} print(cmd, text) if cmd == '/start': telegram_api.send_message( f"""Welcome! You can use this bot to subscribe the deals you interested in.""", chat_id, parse_mode='HTML') telegram_api.send_message(HELP_TEXT, chat_id, parse_mode='HTML') elif cmd == '/getNewestDeal': deal = get_newest_deal_from_db() telegram_api.send_message( f'Here are the newest deals from Dealmoon:\n' f'{deal["title"]}', chat_id) elif cmd == '/mySubscription': subs = storage_user.get_user_keywords(chat_id) if not subs: msg = 'You have not any subscriptions yet. ' \ 'Use /addOneKeyword to add one keyword.' else: msg = 'Your subscriptions: ' +\ ', '.join([f'<b>{s}</b>' for s in subs]) print(msg) telegram_api.send_message(msg, chat_id, parse_mode='HTML') elif cmd == '/addOneKeyword': keyword = text if not keyword: telegram_api.send_message( f'Usage: {cmd} _<your-monitoring-keyword>_', chat_id, parse_mode='Markdown') return {'statusCode': 200, 'body': 'error'} storage_user.add_user_keyword(chat_id, keyword) telegram_api.send_message(f'Keyword <b>{keyword}</b> added.', chat_id, parse_mode='HTML') else: telegram_api.send_message(HELP_TEXT, chat_id) except Exception: return {'statusCode': 200, 'body': 'error'} else: return {'statusCode': 200, 'body': 'ok'} finally: return {'statusCode': 200, 'body': 'finally'}