在帮助下
@ehsan-barkhordar
import pykka
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
updater = Updater(token="token", loop=asyncio.get_event_loop())
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)
app = Flask(__name__)
class ServerActor(pykka.ThreadingActor):
def __init__(self, flask_app):
super(ServerActor, self).__init__()
self.flask_app = flask_app
def on_receive(self, message):
print(message)
def run(self):
self.flask_app.run(host='0.0.0.0', port=5050)
def shutdown_server(self):
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()
@app.route("/", methods=['GET'])
def send_to_user():
message = "hello"
m = TextMessage(message)
bale_bot.send_message(m, Peer('User', "1533910422", "6644828719985087310"), success_callback=success,
failure_callback=failure)
return "message sent"
# class SMStarter():
def start(notification_sender, server_actor_ref):
server_proxy = server_actor_ref.proxy()
future = server_proxy.run()
notification_sender.run()
notification_sender.stop()
start(notification_sender=updater, server_actor_ref=ServerActor.start(flask_app=app))