Beispiel #1
0
def webhook():
    bot.remove_webhook()
    bot.set_webhook(
        url=
        f'https://catch-wildfire-telegram-bot.herokuapp.com/{TELEGRAM_BOT_TOKEN}'
    )
    return "!", 200
Beispiel #2
0
def set_webhook():
    if request.method == "POST":
        bot.remove_webhook()
        bot.set_webhook(url=config.url)
        return "Webhook set successful", 200
    else:
        return f"Get to the main page. <a href=\"/\">Main page</a>", 400
Beispiel #3
0
def set_webhook():
    with open(config.cert_path, 'rb') as crt:
        s = bot.set_webhook(config.webhook_url, certificate=crt)
    if s:
        print(s)
        return 'Webhook setup ok'
    else:
        return 'Webhook setup failed'
Beispiel #4
0
def set_webhook():
    bot.remove_webhook()
    s = bot.set_webhook(WEBHOOK_URL)
    if s:
        print(s)
        return "webhook setup ok"
    else:
        return "webhook setup failed"
Beispiel #5
0
def start():
    on_startup = [lambda _: events.STARTUP_EVENT()]
    on_shutdown = [lambda _: events.SHUTDOWN_EVENT()]

    if config.IS_TEST_ENV:
        from utils import DateTime
        DateTime.fake(2021, 1, 6, 9, 15, 0)
        events.STARTUP_EVENT.register(
            lambda: events.ETHER_BEGIN_EVENT.notify(2, 0))
        bot.start_longpoll(on_startup=on_startup, on_shutdown=on_shutdown)
        # start_server(on_startup=on_startup, on_shutdown=on_shutdown, port=8080)
    else:
        on_startup.append(lambda _: bot.set_webhook(config.WEBHOOK_URL))
        start_server(on_startup=on_startup, on_shutdown=on_shutdown)
Beispiel #6
0
import cherrypy

import config
from bot import bot
from server import WebhookServer

bot.remove_webhook()
bot.set_webhook(url="https://{}:{}/{}/".format(config.SERVER_IP,
                                               config.WEBHOOK_PORT,
                                               config.TOKEN,
                                               ),
                certificate=open(config.WEBHOOK_SSL_CERT, 'r'))

cherrypy.config.update({
    'server.socket_host': config.WEBHOOK_LISTEN,
    'server.socket_port': config.WEBHOOK_PORT,
    'server.ssl_module': 'builtin',
    'server.ssl_certificate': config.WEBHOOK_SSL_CERT,
    'server.ssl_private_key': config.WEBHOOK_SSL_PRIV
})

cherrypy.quickstart(WebhookServer(bot), "/{}/".format(config.TOKEN), {'/': {}})
Beispiel #7
0
def index():
    bot.remove_webhook()
    bot.set_webhook(url="https://{}.herokuapp.com/{}".format(app_name, token))
    return "Hello from bot!", 200
Beispiel #8
0
import cherrypy
import telebot

from bot import config, bot

logger = logging.getLogger('MyTimeTable')


class Server:
    @cherrypy.expose
    def index(self):
        length = int(cherrypy.request.headers['content-length'])
        json_string = cherrypy.request.body.read(length).decode('utf-8')
        update = telebot.types.Update.de_json(json_string)
        bot.process_new_updates([update])

        return ''


if config.use_webhook:
    logger.info('Using webhook to get updates')

    bot.remove_webhook()
    bot.set_webhook(config.webhook_url_base + config.webhook_url_path)

    wsgiapp = cherrypy.Application(Server(), '/', {'/': {}})
else:
    logger.info('Using polling to get updates')
    bot.remove_webhook()
    bot.polling()
Beispiel #9
0
def webhook():
    bot.remove_webhook()
    bot.set_webhook(url="https://{}.glitch.me/{}".format(
        environ['PROJECT_NAME'], environ['TELEGRAM_TOKEN']))
    return "!", 200
def web_hook():
    bot.remove_webhook()
    bot.set_webhook(url='https://lit-eyrie-94912.herokuapp.com/web_hook/' +
                    Config.TELEGRAM_TOKEN)
    return "!", 200
def index():
    bot.remove_webhook()
    bot.set_webhook(url="https://{}.herokuapp.com/{}".format(
        config.APP_NAME, config.API_TOKEN))
    return "Hello from Heroku!", 200
Beispiel #12
0
import flask
import telebot
import config
from bot import bot


WEBHOOK_URL_BASE = "https://{}:{}".format(config.WEBHOOK_HOST, config.WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/{}/".format(config.TOKEN)

bot.remove_webhook()

bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH)


app = flask.Flask(__name__)

@app.route('/', methods=['GET', 'HEAD'])
def index():
    return 'ok'

@app.route(WEBHOOK_URL_PATH, methods=['POST'])
def webhook():
    if flask.request.headers.get('content-type') == 'application/json':
        json_string = flask.request.get_data().decode('utf-8')
        update = telebot.types.Update.de_json(json_string)
        bot.process_new_updates([update])
        return ''
    else:
        flask.abort(403)
Beispiel #13
0
#!/usr/bin/env python

from flask import Flask, request

from bot import bot
from mud import Chatflow
from storage import Storage

import settings

app = Flask(__name__)
bot.set_webhook(url=f"https://{settings.WEBHOOK_HOST}/{settings.TOKEN}",
                certificate=open(settings.CERT, 'rb'))


@app.route('/' + settings.TOKEN, methods=['POST'])
def webhook():
    bot_request = bot.get_player_bot_request(request)
    if bot_request:
        storage = Storage(bot_request.send_callback_factory,
                          cmd_pfx=bot.cmd_pfx)
        player = storage.get_player_state(bot_request.chatkey)
        chatflow = Chatflow(player, storage.world, bot.cmd_pfx)
        if bot_request.process_message(chatflow):  # bot-specific UI commands
            storage.release()
        else:
            chatflow.process_message(bot_request.message_text)
            storage.save()
        bot_request.send_messages()
    return b'OK'
Beispiel #14
0
def webhook():
    url = f'https://mmozgov-python-weather-bot.herokuapp.com/weather_bot{BOT_TOKEN}'
    bot.remove_webhook()
    bot.set_webhook(url=url)
    return 'OK', 200
Beispiel #15
0
        update = telebot.types.Update.de_json(update_json)
        bot.process_new_updates([update])
        return 'ok', 200
    else:
        return ('This is sochnye bitochky bot app')


#Обработчик запросов от телеги к админскому боту
@app.route('/admin_bot', methods=['POST', 'GET'])
def admin_bot_app():
    if request.method == 'POST':
        update_json = request.get_data().decode('utf-8')
        update = telebot.types.Update.de_json(update_json)
        admin_bot.process_new_updates([update])
        return 'ok', 200
    else:
        return ('This is sochnye bitochky admin bot app')


#на всякий случай сбрасываем вебхук (если, например, сменили адрес)
bot.remove_webhook()
admin_bot.remove_webhook()

time.sleep(0.1)

#Устанавливаем вебхуки на ботов
bot.set_webhook(url=BOT_WEBHOOK)
admin_bot.set_webhook(url=ADMIN_BOT_WEBHOOK)

if __name__ == '__main__':
    app.run()
Beispiel #16
0
import os
import http.server
import telebot
from bot import bot

if not os.getenv('HEROKU'):
    if os.getenv('PROXY'):
        telebot.apihelper.proxy = {'https': os.getenv('PROXY')}
    bot.remove_webhook()
    bot.polling()
    bot.set_webhook(os.getenv('APP_URL'))
else:
    class Handler(http.server.BaseHTTPRequestHandler):
        def do_POST(self):
            self.send_response(200)
            self.end_headers()
            content_length = int(self.headers['Content-Length'])
            content = self.rfile.read(content_length).decode('utf-8')

            update = telebot.types.Update.de_json(content)
            bot.process_new_updates([update])

    bot.set_webhook(os.getenv('APP_URL'))
    server_address = ('0.0.0.0', int(os.getenv('PORT') or 5000))
    server = http.server.HTTPServer(server_address, Handler)
    server.serve_forever()
Beispiel #17
0
        except TelegramError:
            pass
    session.commit()
    session.close()


logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)

cleanup_db()

load_posts_from_db(updater.job_queue)
prepare_daily_job(updater.job_queue)

for handler in handlers.all_handlers:
    dispatcher.add_handler(handler)

# updater.start_polling()
updater.start_webhook(
    listen="0.0.0.0",
    port=int(os.environ.get("PORT", "8443")),
    url_path=TOKEN
)
bot.set_webhook(url="https://li465-188.members.linode.com/" + TOKEN)

while True:
    logging.info("Updates in queue: {}".format(updater.update_queue.qsize()))
    logging.info("Forwarding next time: {}".format(bot.forwarding_next_time))
    time.sleep(2.0)

# updater.idle()
Beispiel #18
0
 def webhook():
     bot.remove_webhook()
     bot.set_webhook(url=os.environ["APP_URL"] + TTOKEN)
     return "!", 200
Beispiel #19
0
import cherrypy

import config
from bot import bot
from server import WebhookServer

bot.remove_webhook()
bot.set_webhook(url="https://{}:{}/{}/".format(
    config.SERVER_IP,
    config.WEBHOOK_PORT,
    config.TOKEN,
),
                certificate=open(config.WEBHOOK_SSL_CERT, 'r'))

cherrypy.config.update({
    'server.socket_host': config.WEBHOOK_LISTEN,
    'server.socket_port': config.WEBHOOK_PORT,
    'server.ssl_module': 'builtin',
    'server.ssl_certificate': config.WEBHOOK_SSL_CERT,
    'server.ssl_private_key': config.WEBHOOK_SSL_PRIV
})

cherrypy.quickstart(WebhookServer(bot), "/{}/".format(config.TOKEN), {'/': {}})
Beispiel #20
0
def webhook():
    bot.remove_webhook()
    bot.set_webhook(url=config.boturi + config.token)
    return "!", 200
Beispiel #21
0
def reset_webhook():
    bot.remove_webhook()
    bot.set_webhook(url=webhook_url_base + webhook_url_path)
    return "OK", 200
Beispiel #22
0
def st_webhook():
    bot.remove_webhook()
    bot.set_webhook(CONFIG.SERVER_URL + CONFIG.TOKEN)
    return "!",
Beispiel #23
0
def webhook():
    bot.remove_webhook()
    bot.set_webhook(url=constants.heroku_url + constants.token)
    return "Hello from Heroku!", 200
Beispiel #24
0
def web_hook():
    vk_bot.remove_webhook()
    vk_bot.set_webhook(url='https://vkfilebot.herokuapp.com/' +
                       constants.TOKEN_TELEGRAM)
    return "CONNECTED" + "\n Contact " + "<a href=" + "https://t.me/daniel_nikulin" + ">" + "Daniel" + "<a>", 200
Beispiel #25
0
from flask import Flask, request, abort
from bot import bot
import telebot
import configparser

config = configparser.ConfigParser()
config.read('/home/wanku/itc_moderator_bot/settings.ini')
app = Flask(__name__)

bot.remove_webhook()
bot.set_webhook(url='{}/{}'.format(
    config['DEFAULT']['url_base'],
    config['DEFAULT']['secret']
))


@app.route('/{}'.format(config['DEFAULT']['secret']), methods=["POST"])
def webhook():
    if request.headers.get('content-type') == 'application/json':
        json_string = request.get_data().decode('utf-8')
        update = telebot.types.Update.de_json(json_string)
        bot.process_new_updates([update])
        return ''
    else:
        abort(403)
Beispiel #26
0
def webhook():
    """Set telebot webhook."""

    bot.remove_webhook()
    bot.set_webhook(url="{}{}".format(APP_URL, TOKEN))
    return "Succsess! Webhook is thrown"
def webhook():
    bot.remove_webhook()
    bot.set_webhook(url='https://cuba-weather.herokuapp.com/' + config.token)
    return "!", 200