first month with golang - building telegram chat bot

16
My first month with Golang Building a Chat bot on Telegram

Upload: dan-tran-trong

Post on 07-Jan-2017

1.075 views

Category:

Software


4 download

TRANSCRIPT

Page 1: First month with golang - Building Telegram chat bot

My first month with Golang

Building a Chat bot on Telegram

Page 2: First month with golang - Building Telegram chat bot

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

Programming logic

• If then…else if …. else if…end

• - /start

• - /help

Page 4: First month with golang - Building Telegram chat bot

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

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

Implementation

Page 7: First month with golang - Building Telegram chat bot

Flow chart(2)Telegram

Server Your computer

UsersResponse

Text:*ForceReply: *

KeyboardMarkup:*

Response

Response

Page 8: First month with golang - Building Telegram chat bot

Implementation

Page 9: First month with golang - Building Telegram chat bot

Number of ratingsDays Reviews

1 32 123 354 535 85

Page 10: First month with golang - Building Telegram chat bot

Storebot

Page 11: First month with golang - Building Telegram chat bot

Analytics

• Using redis: to count number of user, words

• Logging and email notification

Page 12: First month with golang - Building Telegram chat bot

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

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

Design logo

Page 15: First month with golang - Building Telegram chat bot

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

What I learnt• Restful API

• Using log and email notification

• Build analytics using redis

• Write a go package

• User experience