First month with golang - Building Telegram chat bot
-
Upload
dan-tran-trong -
Category
Software
-
view
1.076 -
download
4
Transcript of First month with golang - Building Telegram chat bot
![Page 1: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/1.jpg)
My first month with Golang
Building a Chat bot on Telegram
![Page 2: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/2.jpg)
How to start• Get an idea
• Get API key from BotFather
• Run a service from your computer or server in any language
• Programming Logic
![Page 3: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/3.jpg)
Programming logic
• If then…else if …. else if…end
• - /start
• - /help
![Page 4: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/4.jpg)
My bot• - Dictionary bots: @envndictbot @thesaurusdictbot• - Logic:
• If /start : welcome message• If /help: help message• If any word: check database to get definition• If word from group chat: filter bot name
![Page 5: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/5.jpg)
Flow chart(1)Telegram
Server Your computerPolling
Messages request
limit<=100
Users
Message
Polling:/getUpdates?offset=*&limit=*
![Page 6: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/6.jpg)
Implementation
![Page 7: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/7.jpg)
Flow chart(2)Telegram
Server Your computer
UsersResponse
Text:*ForceReply: *
KeyboardMarkup:*
Response
Response
![Page 8: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/8.jpg)
Implementation
![Page 9: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/9.jpg)
Number of ratingsDays Reviews
1 32 123 354 535 85
![Page 10: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/10.jpg)
Storebot
![Page 11: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/11.jpg)
Analytics
• Using redis: to count number of user, words
• Logging and email notification
![Page 12: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/12.jpg)
Analytics1 hi 150
2 hello 105
3 fuck 98
4 sex 72
5 good 63
6 book 59
7 love 58
8 start 55
9 go 30
10 ok 27
11 thesaurus 27
12 stop 21
13 apple 19
14 help 19
15 car 18
![Page 13: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/13.jpg)
Avoid spam
• Using regular expression to validate bot input and reduce work load
• Skip group message which not related to your bot
• Blacklist spammers
![Page 14: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/14.jpg)
Design logo
![Page 15: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/15.jpg)
Libraries• https://storebot.me/
• Bot API https://core.telegram.org/bots/api
• My bot: https://github.com/aladine/envndictbot
• Libraries:
• github.com/rockneurotiko/go-tgbot
• https://github.com/tucnak/telebot
![Page 16: First month with golang - Building Telegram chat bot](https://reader036.fdocuments.in/reader036/viewer/2022081505/587063531a28ab48378b4629/html5/thumbnails/16.jpg)
What I learnt• Restful API
• Using log and email notification
• Build analytics using redis
• Write a go package
• User experience