forked from saniales/golang-crypto-trading-bot
/
telegram_integration.go
53 lines (46 loc) · 1.33 KB
/
telegram_integration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package strategies
import (
"time"
"github.com/saniales/golang-crypto-trading-bot/environment"
"github.com/saniales/golang-crypto-trading-bot/exchanges"
"github.com/saniales/golang-crypto-trading-bot/strategies"
"github.com/sirupsen/logrus"
tb "gopkg.in/tucnak/telebot.v2"
)
var telegramBot *tb.Bot
var telegramIntegrationExample = strategies.IntervalStrategy{
Model: strategies.StrategyModel{
Name: "telegramIntegrationExample",
Setup: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
telegramBot, err := tb.NewBot(tb.Settings{
Token: "TOKEN_HERE",
Poller: &tb.LongPoller{Timeout: 10 * time.Second},
})
if err != nil {
return err
}
telegramBot.Start()
return nil
},
OnUpdate: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
telegramBot.Send(&tb.User{
Username: "YOUR-USERNAME-GROUP-OR-USER",
}, "OMG SOMETHING HAPPENING!!!!!", tb.SendOptions{})
/*
// Optionally it can have options
telegramBot.Send(tb.User{
Username: "YOUR-JOINED-GROUP-USERNAME",
}, "OMG SOMETHING HAPPENING!!!!!", tb.SendOptions{})
*/
return nil
},
OnError: func(err error) {
logrus.Errorf("I Got an error %s", err)
telegramBot.Stop()
},
TearDown: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
telegramBot.Stop()
return nil
},
},
}