Skip to content

Commit

Permalink
Merge pull request #23 from Azizadx/abamitchew/feat/bot-chat
Browse files Browse the repository at this point in the history
Abamitchew/feat/bot chat
  • Loading branch information
amitchew authored Feb 3, 2024
2 parents b555c25 + 6814a70 commit e82cccd
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,7 @@ artifacts/
##webapp and chatbot
telegram/frontend/node_modules/
telegram/chat-bot/bot_flask


##Venv of telegram
telegram/chat-bot/.env
71 changes: 45 additions & 26 deletions telegram/chat-bot/app.py
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()
5 changes: 3 additions & 2 deletions telegram/chat-bot/config.py
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 modified telegram/chat-bot/requirements.txt
Binary file not shown.
45 changes: 36 additions & 9 deletions telegram/frontend/src/components/component/ad_campaign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,39 @@
* This code was generated by v0 by Vercel.
* @see https://v0.dev/t/HrItzW5SGnX
*/
import { Label } from "@/components/ui/label"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import { Button } from "@/components/ui/button"


import { useState } from 'react';
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
import axios from 'axios';

export function AdCampaign() {
const [formData, setFormData] = useState({
advertiserName: '',
productName: '',
campaignBriefs: ''
});

const handleChange = (e:any) => {
const { id, value } = e.target;
setFormData(prevState => ({
...prevState,
[id]: value
}));
};

const handleSubmit = async (e:any) => {
e.preventDefault();
try {
const response = await axios.post('http://127.0.0.1:8001/get-data', formData);
console.log('Server response:', response.data);
} catch (error) {
console.error('Error submitting form:', error); }
};

return (
<section className="w-full py-12 md:py-24 lg:py-32">
<div className="container px-4 md:px-6">
Expand All @@ -22,18 +49,18 @@ export function AdCampaign() {
</p>
</div>
<div className="w-full max-w-sm space-y-2">
<form className="flex flex-col space-y-4">
<form className="flex flex-col space-y-4" onSubmit={handleSubmit}>
<div className="grid w-full gap-1.5">
<Label htmlFor="advertiser-name">Advertiser Name</Label>
<Input id="advertiser-name" placeholder="Enter Advertiser Name" />
<Input id="advertiserName" placeholder="Enter Advertiser Name" onChange={handleChange} value={formData.advertiserName} />
</div>
<div className="grid w-full gap-1.5">
<Label htmlFor="product-name">Product Name</Label>
<Input id="product-name" placeholder="Enter Product Name" />
<Input id="productName" placeholder="Enter Product Name" onChange={handleChange} value={formData.productName} />
</div>
<div className="grid w-full gap-1.5">
<Label htmlFor="campaign-briefs">Campaign Briefs</Label>
<Textarea className="min-h-[100px]" id="campaign-briefs" placeholder="Enter Campaign Briefs" />
<Textarea className="min-h-[100px]" id="campaignBriefs" placeholder="Enter Campaign Briefs" onChange={handleChange} value={formData.campaignBriefs} />
</div>
<Button className="w-full" type="submit">
Submit
Expand All @@ -43,5 +70,5 @@ export function AdCampaign() {
</div>
</div>
</section>
)
);
}

0 comments on commit e82cccd

Please sign in to comment.