def _send_telegram(self): """ send one telegram message per news. :return: """ bot = TelegramBot() for i in range(0, len(self.matching_articles)): current = self.matching_articles[i] label = current.get('label').get('name') articles = current.get('articles') for article in articles: try: msg = "\n" \ "*New News Item for* {}: \n" \ "*Title*: {} \n" \ "*Tags*: {} \n" \ "*Source*: {} \n" \ "*URL*: {} \n".format(label, article.get('title'), article.get('tags'), article.get('source'), article.get('link')) except UnicodeEncodeError as e: msg = "\n" \ "*New News Item for* {}: \n" \ "*Title*: {} \n" \ "*Tags*: {} \n" \ "*Source*: {} \n".format(label, article.get('title'), article.get('tags'), article.get('source')) bot.send_message(msg)
def index(): req = request.get_json() if "message" in req: bot = TelegramBot() response = bot.prepare_response(req) bot.send_message(response) else: response = {} return response
def index(): req = request.get_json() bot = TelegramBot() bot.parse_webhook_data(req) # success = bot.action() message = bot.return_message() final_ans = income_message(str(message)) if (final_ans == 1): success = bot.send_message("Real new , You can safely forward") else: success = bot.send_message("Fake new , kindly report") return jsonify(success=success ) # TODO: Success should reflect the success of the reply
def index(): if request.method == 'POST': data = request.get_json() #print(data) bot = TelegramBot() bot(data) # 사용자의 text 입력 처리 if not 'callback_query' in data.keys(): #사용자가 사진 업로드 했을때는 여기로 if 'photo' in data['message'].keys(): #최초에 프로필 등록하기 위해 사진을 올린 경우 if db.get_single_value(bot.chat_id, "dialog_state") == "profile_image": bot.save_image2db(bot.text) bot.send_message("너를 표현하는 태그를 남겨주면 관심있는 사람들이 볼 수 있어") db.insert_value(bot.chat_id, 'dialog_state', 'appeal_tag') #프로필 사진 변경을 위해 사진을 올린 경우 elif db.get_single_value(bot.chat_id, "dialog_state") == "update": bot.save_image2db(bot.text) result = db.get_userinfo("telegram", str(bot.chat_id)) bot.send_message("너의 정보가 아래와 같이 수정되었어") text = '''{}님이 입력하신 정보는 아래와 같습니다\n성별 : {}\n나이 : {}\n여행지 : {}\n여행기간 : {}\n여행정보 : {}\n''' \ .format(bot.name, result['sex'][0], result['age'][0], result['city'][0], result['start_date'][0] \ + " ~ " + result['end_date'][0], result['appeal_tag'][0]) bot.send_img(result['profile_image'][0], text, button.update_button()) db.insert_value(bot.chat_id, "dialog_state", "update") else: bot.send_message("갑자기 왠 사진??") else: # 사용자 로그 print(bot.name + '(' + str(bot.chat_id) + ')' + '님이 ' + '[' + bot.text + ']' + '를 서버로 보냈습니다') text_controller(bot) # 사용자의 keyboard 입력 처리 else: button_controller(bot) return ''
return reply def get_todays_offer(offer): title = offer["titel"] dish = offer["beschreibung"] price = offer["preis_s"] return parse.quote(f"{title}: {dish} (€{price})"), title == "Nudeltheke" def get_todays_dishes(): r = request.urlopen(dishes_url).read().decode("utf-8") content = json.loads(r) return content["wochentage"][0]["datum"]["angebote"] while True: updates = bot.get_updates(offset=update_id) updates = updates["result"] if updates: for item in updates: update_id = item["update_id"] try: message = item["message"]["text"] except KeyError: message = None from_ = item["message"]["from"]["id"] reply_ = make_reply(message) bot.send_message(from_, reply_)
def test_it_sends_a_message_given_a_chat_id(self): bot = TelegramBot(token='123') bot.send_message('chat_id', 'message') self.bot.send_message.assert_called_once_with('chat_id', 'message')