import os
import asyncio
from aiotraq_bot import TraqHttpBot
from aiotraq_message import TraqMessage, TraqMessageManager
# A component that defines what to send
async def component(am: TraqMessage, payload: str):
am.write("Hello, World!")
am.write(payload)
bot = TraqHttpBot(verification_token=os.getenv("BOT_VERIFICATION_TOKEN"))
# Initialize the manager with bot, token, API URL, and base URL
response = TraqMessageManager(
bot,
os.getenv("BOT_ACCESS_TOKEN"),
"https://q.trap.jp/api/v3",
"https://q.trap.jp"
)
@bot.event("MESSAGE_CREATED")
async def on_message_created(payload) -> None:
channel_id = payload.message.channelId
message = payload.message.plainText
# Execute the component for the specified channel
await response(component, channel_id=channel_id, payload=message)
if __name__ == "__main__":
bot.run(port=8080)