Package: balebot
Bale bot pythonPython SDK and samples forBale bot messenger.Register for an Access TokenYou'll need to create your bot by@Bot_Father. Bot_Father gives you a Token to start.Installationpipinstall-rrequirements.txtUsageimportasynciofrombalebot.filtersimport*frombalebot.handlersimportMessageHandler,CommandHandlerfrombalebot.models.messagesimport*frombalebot.updaterimportUpdaterupdater=Updater(token="Bot_token",loop=asyncio.get_event_loop())bot=updater.botdispatcher=updater.dispatcherNote: You need to set Config.py if you want to use the logger classSimple communication with clientAllows you to hear from client and answer.@dispatcher.message_handler(filters=TextFilter(keywords=["hello"]))# filter text the client enter to botdefhear(bot,update):message=TextMessage('Hello')user_peer=update.get_effective_user()bot.send_message(message,user_peer,success_callback=success,failure_callback=failure)Sending a simple voice message:Note:You should upload the voice file first.Allows you to send a voice message. (You can also send a document in the same way).defsend_voice(bot,update):user_peer=update.get_effective_user()v_message=VoiceMessage(file_id=file_id,access_hash=access_hash,name="Hello",file_size='259969',mime_type="audio/mpeg",duration=20,file_storage_version=1)bot.send_message(v_message,user_peer,success_callback=success,failure_callback=failure)Sending a generic template message:Note:Generic Template MessagesAllows you to add cool text buttons to a general message.defask_question(bot,update):general_message=TextMessage("a message")btn_list=[TemplateMessageButton(text="yes",value="yes",action=0),TemplateMessageButton(text="no",value="no",action=0)]template_message=TemplateMessage(general_message=general_message,btn_list=btn_list)bot.send_message(template_message,user_peer,success_callback=success,failure_callback=failure)Sending a generic purchase message:Allows you send a purchase message. Clients can pay the money requested by the message by pressing "pay" button.@dispatcher.message_handler(PhotoFilter())defpurchase_message(bot,update):message=update.get_effective_message()user_peer=update.get_effective_user()first_purchase_message=PurchaseMessage(msg=message,account_number=6037991067471130,amount=10,money_request_type=MoneyRequestType.normal)bot.send_message(first_purchase_message,user_peer,success_callback=success,failure_callback=failure)dispatcher.finish_conversation(update)visitbale-developersfor more informationChangelog[1.7.14] - 2019-03-02Addedexact_keywords argument to text_filter and template_response_filtertermination signal handlingsengin to channel by nickNamefixedcode examplesbase_url added to updater argumentsset default group shield to off[1.6.12] - 2019-01-08Addedget_quoted_message and get_quoted_sender_peer_id to
FatSeqUpdate for getting replied and forwarded messagesdefault photo and message type limitation for purchase messageget_receipt function to BankMessage for getting receipt info as a named tupleget_receipt and get_quoted_message examplesfixedfilters problemhandle monitoring hash function problemsome code examples[1.5.11] - 2019-01-03Addedadded validator parameter to filters as a callable function to validate the inputsadded text field among with text_message filed to template response message for unifying
with other classes text fieldfixedstate holder problem at stop[1.4.10] - 2018-12-23AddedQuoted Message Handlerdefault action and value for template_message_buttongroup_shield to config for preventing bot to handle updates from group_peersaving bot state_machine to redis db through state_holder and redis configs in configtemplate_message, location_message and contact_message load_from_jsonfixedbot.send_document[1.3.9] - 2018-12-05Addedget_response method in response classIPG payment messagehealthy socket connection[1.2.8] - 2018-09-30AddedSend photo message easier than the past.Send Document message easier than the past.fixednetwork connection