def track_express(message): """ get_season_count text/voice message, all digits means express id. Otherwise sends Turing or refuse message :param message: Telegram message sent by user. :return: None """ if os.name == 'nt': temp = os.environ.get('TMP') else: temp = '/tmp' if message.voice: bot.send_chat_action(message.chat.id, 'record_audio') # download the file file_info = bot.get_file(message.voice.file_id) voice_file = requests.get( 'https://api.telegram.org/file/bot{0}/{1}'.format( TOKEN, file_info.file_path)) file_path = os.path.join(temp, message.voice.file_id + '.ogg') with open(file_path, 'wb') as f: f.write(voice_file.content) message.text = utils.voice_to_text(file_path) if u'4C7' in message.text: bot.send_chat_action(message.chat.id, 'typing') r = utils.reply_refuse() bot.send_message(message.chat.id, r) elif message.text.isdigit(): bot.send_chat_action(message.chat.id, 'typing') r = kuaidi100.receiver(message.text, message.message_id, message.chat.id) if u'单号不存在或者已经过期' in r: bot.reply_to(message, '汝的单号可能刚刚生成,暂无信息,不如稍后试试?') else: bot.reply_to(message, r, parse_mode='Markdown') # use turing bot elif TURING_KEY == '': bot.send_chat_action(message.chat.id, 'typing') r = utils.reply_refuse() bot.send_message(message.chat.id, r) else: bot.send_chat_action(message.chat.id, 'typing') r = turing.send_turing(TURING_KEY, message.text, message.chat.id) bot.send_message(message.chat.id, r) return r
def track_express(message): """ process ordinary message, all digits means express id. Otherwise active Turing or refuse message :param message: Telegram message sent by user. :return: None """ if message.text.isdigit(): bot.send_chat_action(message.chat.id, 'typing') r = kuaidi100.recv(message.text, message.message_id, message.chat.id) bot.send_message(message.chat.id, r) # use turing bot elif TURING_KEY == '': bot.send_chat_action(message.chat.id, 'typing') bot.send_message(message.chat.id, utils.reply_refuse()) else: bot.send_chat_action(message.chat.id, 'typing') r = turing.send_turing(TURING_KEY, message.text, message.chat.id) bot.send_message(message.chat.id, r)