📜 ⬆️ ⬇️

We write Telegram-bot on Go to search Wikipedia

Content
  • Create a bot
  • Write the code
  • We deploy the bot
  • Conclusion

Telegrams are very popular now, and writing bots for him has become a kind of hello world of our day, which is why many people immediately think about writing bot telegrams when thinking about what can be written now.


As a student, I, like all students, often visit Wikipedia in parallel, devoting time and a telegram. It was decided to find a way to combine the presence in the telegram and the opportunity to find the material I needed in Wikipedia, and this bot actually appeared (at the time of writing the bot I didn’t even know that there is a bot for the same purpose from the telegram team).


Create a bot


Go to the BotFather and create a new bot.



Next, we add a command to it with which we can get the number of users who used the bot.



Write the code


Since our bot will live inside the container docker, we will immediately set the environment variables to set the parameters without entering the container.


From non-standard libraries we will need.


go get github.com/Syfaro/telegram-bot-api 

To work with TelegramAPI.


 go get github.com/lib/pq 

To work with Postgres DB.


Create structures.


 type SearchResults struct { ready bool Query string Results []Result } type Result struct { Name, Description, URL string } 

Pay attention to the field ready bool , if the structure is empty, then the value will be false .


Next, enter the data in the structure.


 func (sr *SearchResults) UnmarshalJSON(bs []byte) error { array := []interface{}{} if err := json.Unmarshal(bs, &array); err != nil { return err } sr.Query = array[0].(string) for i := range array[1].([]interface{}) { sr.Results = append(sr.Results, Result{ array[1].([]interface{})[i].(string), array[2].([]interface{})[i].(string), array[3].([]interface{})[i].(string), }) } return nil } 

Now we need a function that will send and receive data.


 func wikipediaAPI(request string) (answer []string) { //   3  s := make([]string, 3) //  if response, err := http.Get(request); err != nil { s[0] = "Wikipedia is not respond" } else { defer response.Body.Close() //  contents, err := ioutil.ReadAll(response.Body) if err != nil { log.Fatal(err) } //    sr := &SearchResults{} if err = json.Unmarshal([]byte(contents), sr); err != nil { s[0] = "Something going wrong, try to change your question" } //      if !sr.ready { s[0] = "Something going wrong, try to change your question" } //           for i := range sr.Results { s[i] = sr.Results[i].URL } } return s } 

Full code
 type SearchResults struct { ready bool Query string Results []Result } type Result struct { Name, Description, URL string } func (sr *SearchResults) UnmarshalJSON(bs []byte) error { array := []interface{}{} if err := json.Unmarshal(bs, &array); err != nil { return err } sr.Query = array[0].(string) for i := range array[1].([]interface{}) { sr.Results = append(sr.Results, Result{ array[1].([]interface{})[i].(string), array[2].([]interface{})[i].(string), array[3].([]interface{})[i].(string), }) } return nil } func wikipediaAPI(request string) (answer []string) { //   3  s := make([]string, 3) //  if response, err := http.Get(request); err != nil { s[0] = "Wikipedia is not respond" } else { defer response.Body.Close() //  contents, err := ioutil.ReadAll(response.Body) if err != nil { log.Fatal(err) } //    sr := &SearchResults{} if err = json.Unmarshal([]byte(contents), sr); err != nil { s[0] = "Something going wrong, try to change your question" } //      if !sr.ready { s[0] = "Something going wrong, try to change your question" } //           for i := range sr.Results { s[i] = sr.Results[i].URL } } return s } 

Due to the fact that we are sending the URL, we need to convert the message from the user into the URL part. Why this is needed, then that the user can send the bot not one but two words separated by a space, we need to replace the space so that it becomes part of the URL. This will be done by the urlEncoded function.


 //       URL func urlEncoded(str string) (string, error) { u, err := url.Parse(str) if err != nil { return "", err } return u.String(), nil } 

Now we need to somehow interact with the database. Create variables in which we will store the data of environment variables for connecting to the database.


 var host = os.Getenv("HOST") var port = os.Getenv("PORT") var user = os.Getenv("USER") var password = os.Getenv("PASSWORD") var dbname = os.Getenv("DBNAME") var sslmode = os.Getenv("SSLMODE") var dbInfo = fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", host, port, user, password, dbname, sslmode) 

And we write the function that will create the table in our database.


 //  users       func createTable() error { //   db, err := sql.Open("postgres", dbInfo) if err != nil { return err } defer db.Close() //  users if _, err = db.Exec(`CREATE TABLE users(ID SERIAL PRIMARY KEY, TIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP, USERNAME TEXT, CHAT_ID INT, MESSAGE TEXT, ANSWER TEXT);`); err != nil { return err } return nil } 

We have created a table, and we need to enter data into it, the next function will do this.


 //    func collectData(username string, chatid int64, message string, answer []string) error { //   db, err := sql.Open("postgres", dbInfo) if err != nil { return err } defer db.Close() //      answ := strings.Join(answer, ", ") // SQL  data := `INSERT INTO users(username, chat_id, message, answer) VALUES($1, $2, $3, $4);` //  SQL  if _, err = db.Exec(data, `@`+username, chatid, message, answ); err != nil { return err } return nil } 

Also let's write a function that will count the number of unique users who wrote the bot, to give this number to users if they send the right command to the bot.


 func getNumberOfUsers() (int64, error) { var count int64 //   db, err := sql.Open("postgres", dbInfo) if err != nil { return 0, err } defer db.Close() //         row := db.QueryRow("SELECT COUNT(DISTINCT username) FROM users;") err = row.Scan(&count) if err != nil { return 0, err } return count, nil } 

Full code
 var host = os.Getenv("HOST") var port = os.Getenv("PORT") var user = os.Getenv("USER") var password = os.Getenv("PASSWORD") var dbname = os.Getenv("DBNAME") var sslmode = os.Getenv("SSLMODE") var dbInfo = fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", host, port, user, password, dbname, sslmode) //    func collectData(username string, chatid int64, message string, answer []string) error { //   db, err := sql.Open("postgres", dbInfo) if err != nil { return err } defer db.Close() //      answ := strings.Join(answer, ", ") // SQL  data := `INSERT INTO users(username, chat_id, message, answer) VALUES($1, $2, $3, $4);` //  SQL  if _, err = db.Exec(data, `@`+username, chatid, message, answ); err != nil { return err } return nil } //  users       func createTable() error { //   db, err := sql.Open("postgres", dbInfo) if err != nil { return err } defer db.Close() //  users if _, err = db.Exec(`CREATE TABLE users(ID SERIAL PRIMARY KEY, TIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP, USERNAME TEXT, CHAT_ID INT, MESSAGE TEXT, ANSWER TEXT);`); err != nil { return err } return nil } func getNumberOfUsers() (int64, error) { var count int64 //   db, err := sql.Open("postgres", dbInfo) if err != nil { return 0, err } defer db.Close() //         row := db.QueryRow("SELECT COUNT(DISTINCT username) FROM users;") err = row.Scan(&count) if err != nil { return 0, err } return count, nil } 

We put everything together


Create a bot.


  //  bot, err := tgbotapi.NewBotAPI(os.Getenv("TOKEN")) if err != nil { panic(err) } //   u := tgbotapi.NewUpdate(0) u.Timeout = 60 //    updates, err := bot.GetUpdatesChan(u) for update := range updates { if update.Message == nil { continue } 

We need to check that the text message comes from the user and our if will do this.


 if reflect.TypeOf(update.Message.Text).Kind() == reflect.String && update.Message.Text != "" 

If the user has sent a sticker or a video, then we will send a message to the user that will indicate that only text messages are suitable.


 //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Use the words for search.") bot.Send(msg) 

Inside if, we nest a switch that will catch the commands:


/ start


 case "/start": //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Hi, i'm a wikipedia bot, i can search information in a wikipedia, send me something what you want find in Wikipedia.") bot.Send(msg) 

/ number_of_users


 case "/number_of_users": if os.Getenv("DB_SWITCH") == "on" { //      num  num, err := getNumberOfUsers() if err != nil { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database error.") bot.Send(msg) } //        ans := fmt.Sprintf("%d peoples used me for search information in Wikipedia", num) //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, ans) bot.Send(msg) } else { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database not connected, so i can't say you how many peoples used me.") bot.Send(msg) } 

and default which will interact with wikipedia and database


 default: //      language := os.Getenv("LANGUAGE") // url   ms, _ := urlEncoded(update.Message.Text) url := ms request := "https://" + language + ".wikipedia.org/w/api.php?action=opensearch&search=" + url + "&limit=3&origin=*&format=json" //       message message := wikipediaAPI(request) if os.Getenv("DB_SWITCH") == "on" { // username, chat_id, message, answer   if err := collectData(update.Message.Chat.UserName, update.Message.Chat.ID, update.Message.Text, message); err != nil { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database error, but bot still working.") bot.Send(msg) } } //        for _, val := range message { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, val) bot.Send(msg) } } 

We create main.


 func main() { time.Sleep(1 * time.Minute) //  if os.Getenv("CREATE_TABLE") == "yes" { if os.Getenv("DB_SWITCH") == "on" { if err := createTable(); err != nil { panic(err) } } } time.Sleep(1 * time.Minute) //  telegramBot() } 

Full code
 func telegramBot() { //  bot, err := tgbotapi.NewBotAPI(os.Getenv("TOKEN")) if err != nil { panic(err) } //   u := tgbotapi.NewUpdate(0) u.Timeout = 60 //    updates, err := bot.GetUpdatesChan(u) for update := range updates { if update.Message == nil { continue } //        if reflect.TypeOf(update.Message.Text).Kind() == reflect.String && update.Message.Text != "" { switch update.Message.Text { case "/start": //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Hi, i'm a wikipedia bot, i can search information in a wikipedia, send me something what you want find in Wikipedia.") bot.Send(msg) case "/number_of_users": if os.Getenv("DB_SWITCH") == "on" { //      num  num, err := getNumberOfUsers() if err != nil { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database error.") bot.Send(msg) } //        ans := fmt.Sprintf("%d peoples used me for search information in Wikipedia", num) //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, ans) bot.Send(msg) } else { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database not connected, so i can't say you how many peoples used me.") bot.Send(msg) } default: //      language := os.Getenv("LANGUAGE") // url   ms, _ := urlEncoded(update.Message.Text) url := ms request := "https://" + language + ".wikipedia.org/w/api.php?action=opensearch&search=" + url + "&limit=3&origin=*&format=json" //       message message := wikipediaAPI(request) if os.Getenv("DB_SWITCH") == "on" { // username, chat_id, message, answer   if err := collectData(update.Message.Chat.UserName, update.Message.Chat.ID, update.Message.Text, message); err != nil { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database error, but bot still working.") bot.Send(msg) } } //        for _, val := range message { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, val) bot.Send(msg) } } } else { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Use the words for search.") bot.Send(msg) } } } func main() { time.Sleep(1 * time.Minute) //  if os.Getenv("CREATE_TABLE") == "yes" { if os.Getenv("DB_SWITCH") == "on" { if err := createTable(); err != nil { panic(err) } } } time.Sleep(1 * time.Minute) //  telegramBot() } 

Summary code
 package main import ( "database/sql" "encoding/json" "fmt" "github.com/Syfaro/telegram-bot-api" _ "github.com/lib/pq" "io/ioutil" "log" "net/http" "net/url" "os" "reflect" "strings" "time" ) type SearchResults struct { ready bool Query string Results []Result } type Result struct { Name, Description, URL string } func (sr *SearchResults) UnmarshalJSON(bs []byte) error { array := []interface{}{} if err := json.Unmarshal(bs, &array); err != nil { return err } sr.Query = array[0].(string) for i := range array[1].([]interface{}) { sr.Results = append(sr.Results, Result{ array[1].([]interface{})[i].(string), array[2].([]interface{})[i].(string), array[3].([]interface{})[i].(string), }) } return nil } func wikipediaAPI(request string) (answer []string) { //   3  s := make([]string, 3) //  if response, err := http.Get(request); err != nil { s[0] = "Wikipedia is not respond" } else { defer response.Body.Close() //  contents, err := ioutil.ReadAll(response.Body) if err != nil { log.Fatal(err) } //    sr := &SearchResults{} if err = json.Unmarshal([]byte(contents), sr); err != nil { s[0] = "Something going wrong, try to change your question" } //      if !sr.ready { s[0] = "Something going wrong, try to change your question" } //           for i := range sr.Results { s[i] = sr.Results[i].URL } } return s } //       URL func urlEncoded(str string) (string, error) { u, err := url.Parse(str) if err != nil { return "", err } return u.String(), nil } var host = os.Getenv("HOST") var port = os.Getenv("PORT") var user = os.Getenv("USER") var password = os.Getenv("PASSWORD") var dbname = os.Getenv("DBNAME") var sslmode = os.Getenv("SSLMODE") var dbInfo = fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", host, port, user, password, dbname, sslmode) //    func collectData(username string, chatid int64, message string, answer []string) error { //   db, err := sql.Open("postgres", dbInfo) if err != nil { return err } defer db.Close() //      answ := strings.Join(answer, ", ") // SQL  data := `INSERT INTO users(username, chat_id, message, answer) VALUES($1, $2, $3, $4);` //  SQL  if _, err = db.Exec(data, `@`+username, chatid, message, answ); err != nil { return err } return nil } //  users       func createTable() error { //   db, err := sql.Open("postgres", dbInfo) if err != nil { return err } defer db.Close() //  users if _, err = db.Exec(`CREATE TABLE users(ID SERIAL PRIMARY KEY, TIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP, USERNAME TEXT, CHAT_ID INT, MESSAGE TEXT, ANSWER TEXT);`); err != nil { return err } return nil } func getNumberOfUsers() (int64, error) { var count int64 //   db, err := sql.Open("postgres", dbInfo) if err != nil { return 0, err } defer db.Close() //         row := db.QueryRow("SELECT COUNT(DISTINCT username) FROM users;") err = row.Scan(&count) if err != nil { return 0, err } return count, nil } func telegramBot() { //  bot, err := tgbotapi.NewBotAPI(os.Getenv("TOKEN")) if err != nil { panic(err) } //   u := tgbotapi.NewUpdate(0) u.Timeout = 60 //    updates, err := bot.GetUpdatesChan(u) for update := range updates { if update.Message == nil { continue } //        if reflect.TypeOf(update.Message.Text).Kind() == reflect.String && update.Message.Text != "" { switch update.Message.Text { case "/start": //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Hi, i'm a wikipedia bot, i can search information in a wikipedia, send me something what you want find in Wikipedia.") bot.Send(msg) case "/number_of_users": if os.Getenv("DB_SWITCH") == "on" { //      num  num, err := getNumberOfUsers() if err != nil { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database error.") bot.Send(msg) } //        ans := fmt.Sprintf("%d peoples used me for search information in Wikipedia", num) //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, ans) bot.Send(msg) } else { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database not connected, so i can't say you how many peoples used me.") bot.Send(msg) } default: //      language := os.Getenv("LANGUAGE") // url   ms, _ := urlEncoded(update.Message.Text) url := ms request := "https://" + language + ".wikipedia.org/w/api.php?action=opensearch&search=" + url + "&limit=3&origin=*&format=json" //       message message := wikipediaAPI(request) if os.Getenv("DB_SWITCH") == "on" { // username, chat_id, message, answer   if err := collectData(update.Message.Chat.UserName, update.Message.Chat.ID, update.Message.Text, message); err != nil { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database error, but bot still working.") bot.Send(msg) } } //        for _, val := range message { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, val) bot.Send(msg) } } } else { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Use the words for search.") bot.Send(msg) } } } func main() { time.Sleep(1 * time.Minute) //  if os.Getenv("CREATE_TABLE") == "yes" { if os.Getenv("DB_SWITCH") == "on" { if err := createTable(); err != nil { panic(err) } } } time.Sleep(1 * time.Minute) //  telegramBot() } 

Let's split the code into separate files so that it is more readable.


wikipedia_api.go
 package main import ( "encoding/json" "io/ioutil" "log" "net/http" ) type SearchResults struct { ready bool Query string Results []Result } type Result struct { Name, Description, URL string } func (sr *SearchResults) UnmarshalJSON(bs []byte) error { array := []interface{}{} if err := json.Unmarshal(bs, &array); err != nil { return err } sr.Query = array[0].(string) for i := range array[1].([]interface{}) { sr.Results = append(sr.Results, Result{ array[1].([]interface{})[i].(string), array[2].([]interface{})[i].(string), array[3].([]interface{})[i].(string), }) } return nil } func wikipediaAPI(request string) (answer []string) { //   3  s := make([]string, 3) //  if response, err := http.Get(request); err != nil { s[0] = "Wikipedia is not respond" } else { defer response.Body.Close() //  contents, err := ioutil.ReadAll(response.Body) if err != nil { log.Fatal(err) } //    sr := &SearchResults{} if err = json.Unmarshal([]byte(contents), sr); err != nil { s[0] = "Something going wrong, try to change your question" } //      if !sr.ready { s[0] = "Something going wrong, try to change your question" } //           for i := range sr.Results { s[i] = sr.Results[i].URL } } return s } 

url_encoder.go
 package main import ( "net/url" ) //       URL func urlEncoded(str string) (string, error) { u, err := url.Parse(str) if err != nil { return "", err } return u.String(), nil } 

db.go
 package main import ( "database/sql" "fmt" _ "github.com/lib/pq" "os" "strings" ) var host = os.Getenv("HOST") var port = os.Getenv("PORT") var user = os.Getenv("USER") var password = os.Getenv("PASSWORD") var dbname = os.Getenv("DBNAME") var sslmode = os.Getenv("SSLMODE") var dbInfo = fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", host, port, user, password, dbname, sslmode) //    func collectData(username string, chatid int64, message string, answer []string) error { //   db, err := sql.Open("postgres", dbInfo) if err != nil { return err } defer db.Close() //      answ := strings.Join(answer, ", ") // SQL  data := `INSERT INTO users(username, chat_id, message, answer) VALUES($1, $2, $3, $4);` //  SQL  if _, err = db.Exec(data, `@`+username, chatid, message, answ); err != nil { return err } return nil } //  users       func createTable() error { //   db, err := sql.Open("postgres", dbInfo) if err != nil { return err } defer db.Close() //  users if _, err = db.Exec(`CREATE TABLE users(ID SERIAL PRIMARY KEY, TIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP, USERNAME TEXT, CHAT_ID INT, MESSAGE TEXT, ANSWER TEXT);`); err != nil { return err } return nil } func getNumberOfUsers() (int64, error) { var count int64 //   db, err := sql.Open("postgres", dbInfo) if err != nil { return 0, err } defer db.Close() //         row := db.QueryRow("SELECT COUNT(DISTINCT username) FROM users;") err = row.Scan(&count) if err != nil { return 0, err } return count, nil } 

telegrambot.go
 package main import ( "fmt" "github.com/Syfaro/telegram-bot-api" "os" "reflect" "time" ) func telegramBot() { //  bot, err := tgbotapi.NewBotAPI(os.Getenv("TOKEN")) if err != nil { panic(err) } //   u := tgbotapi.NewUpdate(0) u.Timeout = 60 //    updates, err := bot.GetUpdatesChan(u) for update := range updates { if update.Message == nil { continue } //        if reflect.TypeOf(update.Message.Text).Kind() == reflect.String && update.Message.Text != "" { switch update.Message.Text { case "/start": //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Hi, i'm a wikipedia bot, i can search information in a wikipedia, send me something what you want find in Wikipedia.") bot.Send(msg) case "/number_of_users": if os.Getenv("DB_SWITCH") == "on" { //      num  num, err := getNumberOfUsers() if err != nil { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database error.") bot.Send(msg) } //        ans := fmt.Sprintf("%d peoples used me for search information in Wikipedia", num) //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, ans) bot.Send(msg) } else { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database not connected, so i can't say you how many peoples used me.") bot.Send(msg) } default: //      language := os.Getenv("LANGUAGE") // url   ms, _ := urlEncoded(update.Message.Text) url := ms request := "https://" + language + ".wikipedia.org/w/api.php?action=opensearch&search=" + url + "&limit=3&origin=*&format=json" //       message message := wikipediaAPI(request) if os.Getenv("DB_SWITCH") == "on" { // username, chat_id, message, answer   if err := collectData(update.Message.Chat.UserName, update.Message.Chat.ID, update.Message.Text, message); err != nil { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Database error, but bot still working.") bot.Send(msg) } } //        for _, val := range message { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, val) bot.Send(msg) } } } else { //  msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Use the words for search.") bot.Send(msg) } } } func main() { time.Sleep(1 * time.Minute) //  if os.Getenv("CREATE_TABLE") == "yes" { if os.Getenv("DB_SWITCH") == "on" { if err := createTable(); err != nil { panic(err) } } } time.Sleep(1 * time.Minute) //  telegramBot() } 

Now when we have our bot we will write a Dockerfile for it.


 FROM alpine ENV LANGUAGE="en" COPY /code/code . RUN apk add --no-cache ca-certificates &&\ chmod +x code EXPOSE 80/tcp CMD [ "./code" ] 

As well as docker-compose.yml in order for us not to have to manually raise the database if we have the database on the same machine as the bot.


 version: '3.5' services: db: image: postgres environment: POSTGRES_PASSWORD: test bot: image: trigun117/wikipedia-telegram-bot environment: CREATE_TABLE: "yes" DB_SWITCH: "on" TOKEN: HOST: db PORT: 5432 USER: postgres PASSWORD: test DBNAME: postgres SSLMODE: disable 

We deploy the bot


Let's deploy the bot on a local PC, Amazon Web Service: EC2 and RDS database, Google Cloud Platform: GCE and SQL database.


Docker-compose


We insert in our docker-compose.yml a token for a bot.



And run docker-compose.



We are waiting for about 3 minutes and our bot is ready to go.


Google Cloud Platform


Go to the SQL section in the GCP and create the database.



In allowed networks, we indicate that traffic can come from any source.



Now we have a database and IP to connect to it.



Next, go to the Compute Engine tab and create an instance on which the bot will be deployed.



Since Google Compute Engine has such a thing as Automation, which allows us to execute any commands on the instance after its creation without our participation, we will use it for a comfortable sweep.


On the Automation tab, we indicate the commands for installing the docker and launching the container with our bot.



 curl -s https://raw.githubusercontent.com/trigun117/TelegramBot-Go/master/installdocker.sh | bash && \ sudo docker run \ -e CREATE_TABLE=yes \ -e DB_SWITCH=on \ -e TOKEN=497014514:AAGKayv3tUxNrFWCmqtEIxKAS1TMvhXGdLE \ -e HOST=35.189.116.57 \ -e PORT=5432 \ -e USER=postgres \ -e PASSWORD=postgres \ -e DBNAME=postgres \ -e SSLMODE=disable \ -d trigun117/wikipedia-telegram-bot 

We are waiting for about 5 minutes and our bot is ready to use.


Amazon Web Service


Create a database.





endpoint .



EC2, Security Groups .



Inbound Edit



Save.


Instances, . .



3 .


 curl -s https://raw.githubusercontent.com/trigun117/TelegramBot-Go/master/installdocker.sh | bash &&\ sudo docker run \ -e CREATE_TABLE=yes \ -e DB_SWITCH=on \ -e TOKEN=497014514:AAGKayv3tUxNrFWCmqtEIxKAS1TMvhXGdLE \ -e HOST=test-habr.c2ugekubflbp.eu-west-2.rds.amazonaws.com \ -e PORT=5432 \ -e USER=postgres \ -e PASSWORD=postgres \ -e DBNAME=postgres \ -e SSLMODE=disable \ -d trigun117/wikipedia-telegram-bot 

Conclusion


, , Go - . .


GitHub


.


')

Source: https://habr.com/ru/post/351060/


All Articles