def main(): res = None try: res = shelve.open('medias.dbm') bot = Client(config.bot_token) logging.info('starting bot...') admin_commands.bot_start_report(bot, res=res) start_bot(bot, res) except Exception as e: logging.exception('Bad things happend!') try: for admin in config.bot_admins: bot.send_text(admin, str(e)) except Exception: pass finally: if res: res.close()
from soroush_python_sdk import Client bot_token = 'your bot token' bot = Client(bot_token) try: messages = bot.get_messages() for message in messages: print("New message from {} \nType: {}\nBody: {}".format(message['from'], message['type'], message['body'])) message['to'] = message['from'] message.pop('from') message.pop('time') [error, success] = bot.send_message(message) if success: print('Message sent successfully') else: print('Sending message failed: {}' .format(error)) except Exception as e: print(e.args[0])
from soroush_python_sdk import Client from os.path import getsize import ntpath bot_token = 'your bot token' bot = Client(bot_token) try: to = 'user chat_id' image_path = 'image path' image_thumbnail_path = 'thumbnail path' [image_error, image_url] = bot.upload_file(image_path) if image_error: print('error in uploading image: {}' .format(image_error)) else: print('image uploaded successfully with url: {}' .format(image_url)) if image_url: [thumbnail_error, thumbnail_url] = bot.upload_file(image_thumbnail_path) if thumbnail_error: print('error in uploading thumbnail: {}' .format(thumbnail_error)) else: print('thumbnail uploaded successfully with url: {}' .format(thumbnail_url)) [error, success] = bot.send_image(to, image_url, ntpath.basename(image_path), getsize(image_path), 512, 512, thumbnail_url, caption='your caption')
from soroush_python_sdk import Client bot_token = 'your bot token' bot = Client(bot_token) try: to = 'user chat_id' [error, success] = bot.send_location(to, 35.7448416, 51.3753212) if success: print('Message sent successfully') else: print('Sending message failed: {}' .format(error)) except Exception as e: print(e.args[0])
from soroush_python_sdk import Client bot_token = 'your bot token' bot = Client(bot_token) try: to = 'user chat_id' [error, success] = bot.send_text(to, 'Your text') if success: print('Message sent successfully') else: print('Sending message failed: {}'.format(error)) except Exception as e: print(e.args[0])
from soroush_python_sdk import Client bot_token = 'your bot token' bot = Client(bot_token) try: to = 'user chat_id' keyboard1 = [ [{ 'command': "1.1", 'text': "button 1" }, { 'command': "1.2", 'text': "button 2" }], [{ 'command': "2.1", 'text': "button 3" }, { 'command': "2.2", 'text': "button 4" }, { 'command': "2.3", 'text': "button 5" }], ] keyboard2 = bot.make_keyboard('Back') keyboard3 = bot.make_keyboard('Button1|Button2|Button3') keyboard4 = bot.make_keyboard(
import ntpath from os.path import getsize from soroush_python_sdk import Client bot_token = 'your bot token' bot = Client(bot_token) try: to = 'user chat_id' file_path = 'your file path' [error, file_url] = bot.upload_file(file_path) if error: print('error in uploading file: {}' .format(error)) else: print('file uploaded successfully with url: {}' .format(file_url)) [error, success] = bot.send_attachment(to, file_url, ntpath.basename(file_path), getsize(file_path), caption='your caption') if success: print('Message sent successfully') else: print('Sending message failed: {}' .format(error)) except Exception as e: print(e.args[0])
from soroush_python_sdk import Client bot_token = 'your bot token' bot = Client(bot_token) try: file_url = 'received file url from server' save_file_path = 'path to save the file' [error, downloaded_file_path] = bot.download_file(file_url, save_file_path) if downloaded_file_path: print( 'file downloaded successfully in {}'.format(downloaded_file_path)) else: print('error in downloading file: {}'.format(error)) except Exception as e: print(e.args[0])
from soroush_python_sdk import Client from os.path import getsize import ntpath bot_token = 'your bot token' bot = Client(bot_token) try: to = 'user chat_id' file_path = 'your file path' file_duration_in_milliseconds = 7000 [error, file_url] = bot.upload_file(file_path) if error: print('error in uploading file: {}' .format(error)) else: print('file uploaded successfully with url: {}' .format(file_url)) [error, success] = bot.send_voice(to, file_url, ntpath.basename(file_path), getsize(file_path), file_duration_in_milliseconds, caption='your caption') if success: print('Message sent successfully') else: print('Sending message failed: {}' .format(error)) except Exception as e:
from soroush_python_sdk import Client DEBUG = False DEBUG_PAGE = 10 bot_token = "jj5nH1BoZJsbHplz2v8DkiUHZv8o-uCn4c6AHJIxYP-OY_kNt63W0qHl6Wph7HhNzkVGXQ6x4IM9YFcWmMdEtf-uBRvnsZF97w78T" \ "8GpG0Bv7SVLIv1FwM-uMKCGv2PBMfBb7flzBMvtlCZ1" user = {'ali': 'NFiDxo8BngUgqnBRPKVqR8jwCqH-38zxDOeDDy_f7bUCOLgHJkJZJJIU75U'} bot_admins = ('NFiDxo8BngUgqnBRPKVqR8jwCqH-38zxDOeDDy_f7bUCOLgHJkJZJJIU75U', ) # '7UhksfDFWrRkKaczg4Y3Wwho4rHNyzUQAenY9a4F5ZCdPJpUKjzMQ1WRerY', #ghodrati # } keyb = { 'main': Client.make_keyboard("صفحه جدید|گزارشات"), 'admin': Client.make_keyboard("/reload|/restart|/load") } VOICE_KEYS = {1: 'سعد الغامدی', 2: 'پرهیزگار'} default_settings = {'voice': 1, 'reminder': 60 * 60} MAX_PAGE = 604 if not DEBUG else DEBUG_PAGE SEJDEH = (528, 597, 480, 416)
from soroush_python_sdk import Client bot_token = 'your bot token' bot = Client(bot_token) try: messages = bot.get_messages() for message in messages: print("New message from {} \nType: {}\nBody: {}".format( message['from'], message['type'], message['body'])) except Exception as e: print(e.args[0])