Created
September 5, 2018 21:49
-
-
Save reflash/125ab8045070ec976770aaa196d96919 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from uuid import uuid4 | |
from aiogram.types import InlineQueryResultGame | |
from backend.settings import BOT_TOKEN | |
def get_ngrok_https(): | |
import json | |
import os | |
os.system("curl http://localhost:4040/api/tunnels 1> tunnels.json 2> /dev/null") | |
with open('tunnels.json') as data_file: | |
datajson = json.load(data_file) | |
for i in datajson['tunnels']: | |
if i['public_url'].startswith('https'): | |
return i['public_url'] | |
return None | |
url = get_ngrok_https() | |
url = url + '/game' | |
from aiogram import Bot, types | |
from aiogram.dispatcher import Dispatcher | |
from aiogram.utils import executor | |
bot = Bot(token=BOT_TOKEN) | |
dp = Dispatcher(bot) | |
game_short_name = '<GAME_SHORT_NAME>' | |
my_game = lambda callback_query: \ | |
callback_query.game_short_name == game_short_name | |
@dp.callback_query_handler(func=my_game) | |
async def send_welcome(callback_query: types.CallbackQuery): | |
await bot.answer_callback_query(callback_query.id, url=url) | |
@dp.inline_handler() | |
async def send_game(inline_query: types.InlineQuery): | |
await bot.answer_inline_query(inline_query.id, | |
[InlineQueryResultGame(id=str(uuid4()), | |
game_short_name=game_short_name)]) | |
if __name__ == '__main__': | |
executor.start_polling(dp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment