Giter Site home page Giter Site logo

bale-bot-samples's Introduction

Bale bot python samples

Build Status

Python samples for Bale messenger.

About

This Samples are in five parts:

  • simple_hear
  • text_conversion
  • photo_voice_conversion
  • document_conversion
  • purchase_conversion

The functions return the full JSON body of the actual API call to Bale.

Register for an Access Token

You'll need to create your bot by @Bot_Father, Bot_Father, give you a Token.

Installation

pip install -r requirements.txt

DEPRECATED

use new api exmaples

Usage

import asyncio

from balebot.filters import *
from balebot.handlers import MessageHandler, CommandHandler
from balebot.models.messages import *
from balebot.updater import Updater

updater = Updater(token="Your_Bot_Token_You_Give_from_BotFather",
                  loop=asyncio.get_event_loop())
dispatcher = updater.dispatcher

Note: you need set Config.py if you want to get logger

Sending a generic simple message:

Note:Simple bot hear function

allows you to hear and answer the client.

@dispatcher.message_handler(filters=TextFilter(keywords=["hello"]))  # filter text the client enter to bot
def hear(bot, update):
    message = TextMessage('Hello')
    user_peer = update.get_effective_user()
    bot.send_message(message, user_peer, success_callback=success, failure_callback=failure)

Output:

Generic Bot Output

Sending a simple voice message:

Note:You should upload it first!

allows you to send voice message(you can send a document in a same way).

def send_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)

Output:

Generic Bot Output

Sending a generic template message:

Note:Generic Template Messages

allows you to add cool text buttons, to a general text message.

def ask_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)

Output:

Sending a generic purchase message:

allows you send purchase message that clint can pay it by press "pay" button.

@dispatcher.message_handler(PhotoFilter())
def purchase_message(bot, update):
    message = "your message"
    user_peer = update.get_effective_user()
    first_purchase_message = PurchaseMessage(msg=message, account_number="your cart number", amount="how much do you want to ask",
                                             money_request_type=MoneyRequestType.normal)
    bot.send_message(first_purchase_message, user_peer, success_callback=success, failure_callback=failure)
    dispatcher.finish_conversation()

Thanks!

bale-bot-samples's People

Contributors

baleadmin avatar ghiac avatar masoodbayati avatar naderabolfazli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.