diff --git a/Part_1/Tinsae/Dockerfile b/Part_1/Tinsae/Dockerfile new file mode 100644 index 0000000..b9e89db --- /dev/null +++ b/Part_1/Tinsae/Dockerfile @@ -0,0 +1,13 @@ +# Choosing an image for you container. +FROM python:3.11.0 +# Setting your working directory +WORKDIR /app +# This command would copy EVERY FILE from your project folder into your container, so be careful. +COPY . /app +# Installing needed packages and dependencies.** +RUN pip install -r requirements.txt +# This command basically executes your main file with Python. +CMD ["python", "main.py"] +# Setting a port for your app communications with Telegram servers. + +EXPOSE 80/tcp \ No newline at end of file diff --git a/Part_1/Tinsae/Readme.md b/Part_1/Tinsae/Readme.md new file mode 100644 index 0000000..3653c11 --- /dev/null +++ b/Part_1/Tinsae/Readme.md @@ -0,0 +1,5 @@ +# Implementation of this example bot is deployed and it is found by the telegram handle [@A2SV_Remote_Part_1_Example_bot](https://t.me/A2SV_Remote_Part_1_Example_bot) + +# Done by: Blen +# Bot Commands implemented: `/start` +# Update to check if webhook is working properly \ No newline at end of file diff --git a/Part_1/Tinsae/__init__.py b/Part_1/Tinsae/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Part_1/Tinsae/bot/__init__.py b/Part_1/Tinsae/bot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Part_1/Tinsae/bot/bot_instance.py b/Part_1/Tinsae/bot/bot_instance.py new file mode 100644 index 0000000..0cee574 --- /dev/null +++ b/Part_1/Tinsae/bot/bot_instance.py @@ -0,0 +1,10 @@ +import os +from aiogram import Bot, types + +from config import TOKEN_API + + +bot = Bot( + token=TOKEN_API, + parse_mode='HTML' +) \ No newline at end of file diff --git a/Part_1/Tinsae/bot/handlers/__init__.py b/Part_1/Tinsae/bot/handlers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Part_1/Tinsae/bot/handlers/message_handlers.py b/Part_1/Tinsae/bot/handlers/message_handlers.py new file mode 100644 index 0000000..cf97597 --- /dev/null +++ b/Part_1/Tinsae/bot/handlers/message_handlers.py @@ -0,0 +1,21 @@ +from aiogram.filters import Command +from aiogram import Router, types +from aiogram.utils.keyboard import InlineKeyboardBuilder + +# from bot.config import BotConfig + +message_router = Router() + + +@message_router.message(Command('start')) +async def start_handler(message: types.Message): + await message.reply("Hello Welcome to A2SV Remote Part1 By Tinsae Bot") + +@message_router.message(Command('help')) +async def start_handler(message: types.Message): + await message.reply("Hello, This is a Help command\n type /start - to get started\n /chat - to start chatting") + + +@message_router.message(Command('chat')) +async def start_handler(message: types.Message): + await message.reply("coming soon............ :) ") \ No newline at end of file diff --git a/Part_1/Tinsae/config.py b/Part_1/Tinsae/config.py new file mode 100644 index 0000000..076a436 --- /dev/null +++ b/Part_1/Tinsae/config.py @@ -0,0 +1 @@ +TOKEN_API="6703285018:AAGJj1nviQJ8zmu0m9XmMOnAQp4Bgdj8hVQ" \ No newline at end of file diff --git a/Part_1/Tinsae/main.py b/Part_1/Tinsae/main.py new file mode 100644 index 0000000..eec7283 --- /dev/null +++ b/Part_1/Tinsae/main.py @@ -0,0 +1,28 @@ +import asyncio + +from aiogram import Dispatcher + +from bot.bot_instance import bot +from bot.handlers.message_handlers import message_router + + +def register_routers(dp: Dispatcher) -> None: + """Registers routers""" + + dp.include_router(message_router) + + +async def main() -> None: + """The main function which will execute our event loop and start polling.""" + + dp = Dispatcher() + + print('Bot Starting....') + register_routers(dp) + print("Polling ....") + + await dp.start_polling(bot) + + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file diff --git a/Part_1/Tinsae/requirements.txt b/Part_1/Tinsae/requirements.txt new file mode 100644 index 0000000..5b79c5f Binary files /dev/null and b/Part_1/Tinsae/requirements.txt differ diff --git a/Part_2/Tinsae/Dockerfile b/Part_2/Tinsae/Dockerfile new file mode 100644 index 0000000..b9e89db --- /dev/null +++ b/Part_2/Tinsae/Dockerfile @@ -0,0 +1,13 @@ +# Choosing an image for you container. +FROM python:3.11.0 +# Setting your working directory +WORKDIR /app +# This command would copy EVERY FILE from your project folder into your container, so be careful. +COPY . /app +# Installing needed packages and dependencies.** +RUN pip install -r requirements.txt +# This command basically executes your main file with Python. +CMD ["python", "main.py"] +# Setting a port for your app communications with Telegram servers. + +EXPOSE 80/tcp \ No newline at end of file diff --git a/Part_2/Tinsae/Readme.md b/Part_2/Tinsae/Readme.md new file mode 100644 index 0000000..0bf3397 --- /dev/null +++ b/Part_2/Tinsae/Readme.md @@ -0,0 +1,6 @@ +# Implementation of this example bot is deployed and it is found by the telegram handle [@A2SV_Remote_Part1_By_Tinsae_bot] +(https://t.me/A2SV_Remote_Part2_By_Tinsae_bot) + +# Done by: Tinsae B +# Bot Commands implemented: +#`/start`, diff --git a/Part_2/Tinsae/__init__.py b/Part_2/Tinsae/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Part_2/Tinsae/bot/__init__.py b/Part_2/Tinsae/bot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Part_2/Tinsae/bot/bot_instance.py b/Part_2/Tinsae/bot/bot_instance.py new file mode 100644 index 0000000..dd34dc4 --- /dev/null +++ b/Part_2/Tinsae/bot/bot_instance.py @@ -0,0 +1,20 @@ +import os +from aiogram import Bot, types + +from config import TOKEN_API +# Use the commented code below if you store the token api in .env +# from dotenv import load_dotenv +# load_dotenv() + +# For hosting on pythonanywhere use the following commented code +# from aiogram.client.session.aiohttp import AiohttpSession +# bot = Bot( +# token=TOKEN_API, +# parse_mode='HTML', +# session=AiohttpSession(proxy='http://proxy.server:3128') +# ) + +bot = Bot( + token=TOKEN_API, + parse_mode='HTML' +) \ No newline at end of file diff --git a/Part_2/Tinsae/bot/callbacks/__init__.py b/Part_2/Tinsae/bot/callbacks/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Part_2/Tinsae/bot/callbacks/callback.py b/Part_2/Tinsae/bot/callbacks/callback.py new file mode 100644 index 0000000..12dbecd --- /dev/null +++ b/Part_2/Tinsae/bot/callbacks/callback.py @@ -0,0 +1,21 @@ +from aiogram.filters import Command +from aiogram import Router, types +from aiogram.utils.keyboard import InlineKeyboardBuilder +from ..keyboards import keyboard + + +callback_router = Router() + +## +@callback_router.callback_query(lambda c: c.data == "register_phone") +async def process_register_phone(callback_query: types.CallbackQuery): + await callback_query.message.answer("Please share your phone number", reply_markup=ReplyKeyboardRemove()) + +## +@callback_router.callback_query(lambda c: c.data.startswith("action_1")) +async def process_callback_respond_to_action1(callback_query: types.CallbackQuery): + await callback_query.message.answer(f"you picked {callback_query.data}") + +@callback_router.callback_query(lambda c: c.data.startswith("action_2")) +async def process_callback_respond_to_action1(callback_query: types.CallbackQuery): + await callback_query.message.answer(f"you picked {callback_query.data}") diff --git a/Part_2/Tinsae/bot/handlers/__init__.py b/Part_2/Tinsae/bot/handlers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Part_2/Tinsae/bot/handlers/message_handlers.py b/Part_2/Tinsae/bot/handlers/message_handlers.py new file mode 100644 index 0000000..f5f4a6d --- /dev/null +++ b/Part_2/Tinsae/bot/handlers/message_handlers.py @@ -0,0 +1,15 @@ +from aiogram.filters import Command +from aiogram import Router, types +from aiogram.utils.keyboard import InlineKeyboardBuilder + +from ..keyboards import keyboard + + + +message_router = Router() + +##Start handler +@message_router.message(Command('start')) +async def start_handler(message: types.Message): + await message.answer("Hello Welcome to Telegram Bot Development Phase", reply_markup=keyboard.register_buttons_reply_keyboard) + diff --git a/Part_2/Tinsae/bot/keyboards/__init__.py b/Part_2/Tinsae/bot/keyboards/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Part_2/Tinsae/bot/keyboards/keyboard.py b/Part_2/Tinsae/bot/keyboards/keyboard.py new file mode 100644 index 0000000..1be5318 --- /dev/null +++ b/Part_2/Tinsae/bot/keyboards/keyboard.py @@ -0,0 +1,66 @@ + +from aiogram.types import ReplyKeyboardMarkup, InlineKeyboardMarkup, KeyboardButton, InlineKeyboardButton + +first_reply_keyboard = ReplyKeyboardMarkup( + keyboard=[ + [ + KeyboardButton(text="👋 Register!") + ], + [ + KeyboardButton(text="ℹ About Me") + ] + ], + resize_keyboard=True, + one_time_keyboard=True, + input_field_placeholder="dtrial", + selective=True +) + + +first_inline_keyboard = InlineKeyboardMarkup( + inline_keyboard=[ + [ + InlineKeyboardButton(text="👋 Register!", url="https://youtu.be/CBJiJcgmDmM"), + InlineKeyboardButton(text="ℹ About Me", url="https://youtu.be/CBJiJcgmDmM") + ] + ] +) + +# inline keyboard with callback +second_inline_keyboard = InlineKeyboardMarkup( + inline_keyboard=[ + [ + InlineKeyboardButton(text="action 1", callback_data="action_1"), + InlineKeyboardButton(text="action 2", callback_data="action_2") + ] + ] +) + +register_buttons_reply_keyboard = ReplyKeyboardMarkup( + keyboard=[ + [ + KeyboardButton(text="Register phone"), + KeyboardButton(text="Register location") + ], + [ + KeyboardButton(text="Custom Button 1"), + KeyboardButton(text="Custom Button 2") + ] + ], + resize_keyboard=True, + one_time_keyboard=True, + selective=True +) + +# Inline keyboard with Register phone and custom buttons +register_buttons_inline_keyboard = InlineKeyboardMarkup( + inline_keyboard=[ + [ + InlineKeyboardButton(text="Register phone", callback_data="register_phone"), + InlineKeyboardButton(text="Custom Button 1", callback_data="custom_button_1") + ], + [ + InlineKeyboardButton(text="Custom Button 2", callback_data="custom_button_2") + ] + ] +) \ No newline at end of file diff --git a/Part_2/Tinsae/config.py b/Part_2/Tinsae/config.py new file mode 100644 index 0000000..45dff13 --- /dev/null +++ b/Part_2/Tinsae/config.py @@ -0,0 +1 @@ +TOKEN_API="6722511851:AAEgrPqkQVmAApx9KDZ7Xxk9hrqo322rCaw" \ No newline at end of file diff --git a/Part_2/Tinsae/main.py b/Part_2/Tinsae/main.py new file mode 100644 index 0000000..5d5726f --- /dev/null +++ b/Part_2/Tinsae/main.py @@ -0,0 +1,32 @@ +import asyncio + +from aiogram import Dispatcher + +from bot.bot_instance import bot +from bot.handlers.message_handlers import message_router +from bot.callbacks.callback import callback_router + + +def register_routers(dp: Dispatcher) -> None: + """Registers routers""" + + dp.include_router(message_router) + + # callback routers + dp.include_router(callback_router) + + +async def main() -> None: + """The main function which will execute our event loop and start polling.""" + + dp = Dispatcher() + + print('Bot Starting....') + register_routers(dp) + print("Polling ....") + + await dp.start_polling(bot) + + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file diff --git a/Part_2/Tinsae/requirements.txt b/Part_2/Tinsae/requirements.txt new file mode 100644 index 0000000..5b79c5f Binary files /dev/null and b/Part_2/Tinsae/requirements.txt differ