title: How to use Flask app with BaleBot for send message to users
body: <p>I want to use Flask app for getting request to send message Bale users.</p>
  
  <p>this code is work! BaleBot respond user message and Flask app respond request. but <code>bot.send_message</code> in <code>def send_to_user</code> not work!</p>
  
  <p>for example if i send a message (any thing) in Bale to my bot, his respond.
  and if i send a request to Flask such <code>curl -X POST 127.0.0.1:5000/send/user -d 'bale_id=1533910422&amp;access_hash=6644828719985087310&amp;message=text'</code>, Flask was respond.</p>
  
  <pre><code>import os
  
  import asyncio
  from flask import Flask
  from flask import request
  from balebot.handlers import *
  from balebot.filters import *
  from balebot.models.base_models import Peer
  from balebot.models.messages import *
  from balebot.updater import Updater
  from balebot.config import Config
  from threading import Thread
  
  import zbxbale_settings
  
  Config.log_level = zbxbale_settings.LOG_LEVEL
  
  updater = Updater(token=zbxbale_settings.bale_key, loop=asyncio.get_event_loop())
  # updater = Updater(token=zbxbale_settings.bale_key)
  dispatcher = updater.dispatcher
  bale_bot = updater.bot
  
  
  def success(result, err):
      print("success : ", result)
      print("success : ", err)
  
  
  def failure(result, err):
      print("failure : ", result)
  
  
  @dispatcher.command_handler("/start")
  def start_command(bot, update):
      message = update.get_effective_message()
      bot.respond(update, message, success_callback=success, failure_callback=failure)
  
  
  @dispatcher.default_handler()
  def default_handler(bot, update):
      message = update.get_effective_message()
      message.text += " not recognized"
      bot.respond(update, message, success_callback=success, failure_callback=failure)
  
  
  app = Flask(__name__)
  
  
  @app.route("/")
  def hello():
      return "Hello"
  
  
  @app.route("/send/user", methods=['POST'])
  def send_to_user():
      bale_id = request.form['bale_id']
      access_hash = request.form['access_hash']
      message = request.form['message']
      p = Peer('User', bale_id, access_hash)
      m = TextMessage(message)
      bale_bot.send_message(m, p, success_callback=success, failure_callback=failure)
      return "Hello World!"
  
  
  @app.route("/send/group", methods=['POST'])
  def send_to_group():
      bale_id = request.form['bale_id']
      access_hash = request.form['access_hash']
      return "Hello World!"
  
  
  from multiprocessing import Process
  
  
  p = Process(target=app.run, args=())
  q = Process(target=updater.run, args=())
  
  q.start()
  p.start()
  # q.join()
  # p.join()
  # app.run()
  # updater.run()
  
  p = Peer('User', "1533910422", "6644828719985087310")
  m = TextMessage("salam")
  updater.bot.send_message(m, p, success_callback=success, failure_callback=failure)
  </code></pre>