-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from Azizadx/abamitchew/feat/bot-chat
Abamitchew/feat/bot chat
- Loading branch information
Showing
5 changed files
with
88 additions
and
37 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,55 @@ | ||
import telebot | ||
from telebot import types | ||
from config import TELEGRAM_TOKEN | ||
from config import BASE_URL as BaseUrl | ||
# WebApp_URL | ||
|
||
BOT_TOKEN = TELEGRAM_TOKEN | ||
BASE_URL = BaseUrl | ||
import logging | ||
|
||
bot = telebot.TeleBot(BOT_TOKEN) | ||
from telegram import KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, Update, WebAppInfo | ||
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters | ||
|
||
keyboard_markup = types.ReplyKeyboardMarkup(resize_keyboard=True) | ||
button1 = types.KeyboardButton("About") | ||
button2 = types.KeyboardButton("Help") | ||
keyboard_markup.add(button1, button2) | ||
# url_web_app=WebApp_URL | ||
token=TELEGRAM_TOKEN | ||
# Enable logging | ||
logging.basicConfig( | ||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO | ||
) | ||
# set higher logging level for httpx to avoid all GET and POST requests being logged | ||
logging.getLogger("httpx").setLevel(logging.WARNING) | ||
|
||
# Define inline keyboard | ||
inline_keyboard = types.InlineKeyboardMarkup() | ||
webapp_button = types.InlineKeyboardButton(text="Open Web App", url=BASE_URL) | ||
inline_keyboard.add(webapp_button) | ||
logger = logging.getLogger(__name__) | ||
|
||
def handle_start(message): | ||
bot.reply_to(message, "Hello! Welcome to AdBar", reply_markup=keyboard_markup) | ||
|
||
def handle_message(message): | ||
if message.text == "About": | ||
bot.reply_to(message, "AiQEM is an African startup focused on AI and Blockchain business solutions") | ||
elif message.text == "Help": | ||
bot.reply_to(message, "Help is on the way.....") | ||
elif message.text == "Open Web App": | ||
bot.reply_to(message, "Get Started:", reply_markup=inline_keyboard) | ||
# Define a `/start` command handler. | ||
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | ||
"""Send a message with a button that opens a the web app.""" | ||
await update.message.reply_text( | ||
"Click to open Web-App", | ||
reply_markup=ReplyKeyboardMarkup.from_button( | ||
KeyboardButton( | ||
text="Open AiQEM Web-App ", | ||
web_app=WebAppInfo(url="https://aqim-web-app.vercel.app"), | ||
) | ||
), | ||
) | ||
# Define a `/stop` command handler. | ||
def stop(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | ||
"""Stop the bot.""" | ||
update.message.reply_text('Bot stopped.') | ||
context.application.stop() | ||
|
||
|
||
|
||
def main() -> None: | ||
"""Start the bot.""" | ||
# Create the Application and pass it your bot's token. | ||
application = Application.builder().token(TELEGRAM_TOKEN).build() | ||
|
||
application.add_handler(CommandHandler("start", start)) | ||
application.add_handler(CommandHandler("stop", stop)) | ||
|
||
|
||
# Run the bot until the user presses Ctrl-C | ||
application.run_polling(allowed_updates=Update.ALL_TYPES) | ||
|
||
def main(): | ||
bot.polling(none_stop=True, interval=10) # Poll every 5 seconds | ||
|
||
if __name__ == "__main__": | ||
main() | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
TELEGRAM_TOKEN = os.getenv(BOT_TOKEN) | ||
BASE_URL = os.getenv(URL) | ||
TELEGRAM_TOKEN=os.getenv('TELEGRAM_TOKEN') | ||
|
Binary file not shown.
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