Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tinsae.task.2 #46

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Part_1/Tinsae/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions Part_1/Tinsae/Readme.md
Original file line number Diff line number Diff line change
@@ -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
Empty file added Part_1/Tinsae/__init__.py
Empty file.
Empty file added Part_1/Tinsae/bot/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions Part_1/Tinsae/bot/bot_instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os
from aiogram import Bot, types

from config import TOKEN_API


bot = Bot(
token=TOKEN_API,
parse_mode='HTML'
)
Empty file.
21 changes: 21 additions & 0 deletions Part_1/Tinsae/bot/handlers/message_handlers.py
Original file line number Diff line number Diff line change
@@ -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............ :) ")
1 change: 1 addition & 0 deletions Part_1/Tinsae/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TOKEN_API="6703285018:AAGJj1nviQJ8zmu0m9XmMOnAQp4Bgdj8hVQ"
28 changes: 28 additions & 0 deletions Part_1/Tinsae/main.py
Original file line number Diff line number Diff line change
@@ -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())
Binary file added Part_1/Tinsae/requirements.txt
Binary file not shown.
13 changes: 13 additions & 0 deletions Part_2/Tinsae/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions Part_2/Tinsae/Readme.md
Original file line number Diff line number Diff line change
@@ -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`,
Empty file added Part_2/Tinsae/__init__.py
Empty file.
Empty file added Part_2/Tinsae/bot/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions Part_2/Tinsae/bot/bot_instance.py
Original file line number Diff line number Diff line change
@@ -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'
)
Empty file.
21 changes: 21 additions & 0 deletions Part_2/Tinsae/bot/callbacks/callback.py
Original file line number Diff line number Diff line change
@@ -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}")
Empty file.
15 changes: 15 additions & 0 deletions Part_2/Tinsae/bot/handlers/message_handlers.py
Original file line number Diff line number Diff line change
@@ -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)

Empty file.
66 changes: 66 additions & 0 deletions Part_2/Tinsae/bot/keyboards/keyboard.py
Original file line number Diff line number Diff line change
@@ -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")
]
]
)
1 change: 1 addition & 0 deletions Part_2/Tinsae/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TOKEN_API="6722511851:AAEgrPqkQVmAApx9KDZ7Xxk9hrqo322rCaw"
32 changes: 32 additions & 0 deletions Part_2/Tinsae/main.py
Original file line number Diff line number Diff line change
@@ -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())
Binary file added Part_2/Tinsae/requirements.txt
Binary file not shown.