Date post: | 07-Jan-2017 |
Category: |
Software |
Upload: | dan-tran-trong |
View: | 1,073 times |
Download: | 4 times |
My first month with Golang
Building a Chat bot on Telegram
How to start• Get an idea
• Get API key from BotFather
• Run a service from your computer or server in any language
• Programming Logic
Programming logic
• If then…else if …. else if…end
• - /start
• - /help
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
Flow chart(1)Telegram
Server Your computerPolling
Messages request
limit<=100
Users
Message
Polling:/getUpdates?offset=*&limit=*
Implementation
Flow chart(2)Telegram
Server Your computer
UsersResponse
Text:*ForceReply: *
KeyboardMarkup:*
Response
Response
Implementation
Number of ratingsDays Reviews
1 32 123 354 535 85
Storebot
Analytics
• Using redis: to count number of user, words
• Logging and email notification
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
Avoid spam
• Using regular expression to validate bot input and reduce work load
• Skip group message which not related to your bot
• Blacklist spammers
Design logo
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
What I learnt• Restful API
• Using log and email notification
• Build analytics using redis
• Write a go package
• User experience