DEV Community

Nurjalol
Nurjalol

Posted on

 

AI makes telegram bot with aiogram! ๐Ÿคฏ

I tried make telegram bot with AI(ChatGPT). And it works!
Input:

Create aiogram bot in python it could:
- When user sends "emoji" bot replys a random emoji
Enter fullscreen mode Exit fullscreen mode

Output:

from aiogram import Bot, Dispatcher, executor, types

# Initialize bot and dispatcher
bot = Bot(token="2132793876:AAGsWvWHejeFpitoGZ9ujvlSsXe0hOeJSvk")
dp = Dispatcher(bot)

# Import random to generate a random emoji
import random


# Emoji list
EmojiList = ["๐Ÿ˜„", "๐Ÿ˜†", "๐Ÿ˜Š", "๐Ÿ˜Ž", "๐Ÿ˜",
             "๐Ÿ˜š", "๐Ÿ˜œ", "๐Ÿ˜"]

# On message handler
@dp.message_handler()
async def message_handler(message: types.Message):
    # Reply random emoji
    await message.answer(random.choice(EmojiList))

# Start command
if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)
Enter fullscreen mode Exit fullscreen mode

And this code had no bugs ๐Ÿชฒ๐Ÿคฏ

Top comments (1)

Collapse
 
jalol_dev profile image
Nurjalol

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ

An Animated Guide to Node.js Event Loop

Node.js doesnโ€™t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.