Избавился от Redis и убрал отправку сообщений в crisp
This commit is contained in:
parent
ec74632c02
commit
35e3d54ea3
@ -4,7 +4,3 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
volumes:
|
volumes:
|
||||||
- /root/config.yml:/app/config.yml
|
- /root/config.yml:/app/config.yml
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
db:
|
|
||||||
image: redis
|
|
||||||
|
30
main.go
30
main.go
@ -8,15 +8,15 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/crisp-im/go-crisp-api/crisp"
|
"github.com/crisp-im/go-crisp-api/crisp"
|
||||||
"github.com/go-redis/redis"
|
|
||||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"github.com/spf13/viper"
|
|
||||||
"github.com/l0sted/Crisp_Telegram_bot/utils"
|
"github.com/l0sted/Crisp_Telegram_bot/utils"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var bot *tgbotapi.BotAPI
|
var bot *tgbotapi.BotAPI
|
||||||
var client *crisp.Client
|
var client *crisp.Client
|
||||||
var redisClient *redis.Client
|
|
||||||
|
// var redisClient *redis.Client
|
||||||
var config *viper.Viper
|
var config *viper.Viper
|
||||||
|
|
||||||
// CrispMessageInfo stores the original message
|
// CrispMessageInfo stores the original message
|
||||||
@ -35,6 +35,7 @@ func (s *CrispMessageInfo) UnmarshalBinary(data []byte) error {
|
|||||||
return json.Unmarshal(data, s)
|
return json.Unmarshal(data, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func contains(s []interface{}, e int64) bool {
|
func contains(s []interface{}, e int64) bool {
|
||||||
for _, a := range s {
|
for _, a := range s {
|
||||||
if int64(a.(int)) == e {
|
if int64(a.(int)) == e {
|
||||||
@ -43,6 +44,8 @@ func contains(s []interface{}, e int64) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
//from tg to crisp
|
//from tg to crisp
|
||||||
func replyToUser(update *tgbotapi.Update) {
|
func replyToUser(update *tgbotapi.Update) {
|
||||||
if update.Message.ReplyToMessage == nil {
|
if update.Message.ReplyToMessage == nil {
|
||||||
@ -51,7 +54,7 @@ func replyToUser(update *tgbotapi.Update) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := redisClient.Get(strconv.Itoa(update.Message.ReplyToMessage.MessageID)).Result()
|
// res, err := redisClient.Get(strconv.Itoa(update.Message.ReplyToMessage.MessageID)).Result()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "ERROR: "+err.Error())
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "ERROR: "+err.Error())
|
||||||
@ -80,27 +83,30 @@ func replyToUser(update *tgbotapi.Update) {
|
|||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "回复成功!")
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "回复成功!")
|
||||||
bot.Send(msg)
|
bot.Send(msg)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
//from crisp to tg
|
//from crisp to tg
|
||||||
func sendMsgToAdmins(text string, WebsiteID string, SessionID string) {
|
func sendMsgToAdmins(text string, WebsiteID string, SessionID string) {
|
||||||
for _, id := range config.Get("admins").([]interface{}) {
|
for _, id := range config.Get("admins").([]interface{}) {
|
||||||
msg := tgbotapi.NewMessage(int64(id.(int)), text)
|
msg := tgbotapi.NewMessage(int64(id.(int)), text)
|
||||||
msg.ParseMode = "Markdown"
|
msg.ParseMode = "Markdown"
|
||||||
sent, _ := bot.Send(msg)
|
sent, _ := bot.Send(msg)
|
||||||
|
log.Println(strconv.Itoa(sent.MessageID))
|
||||||
|
/*
|
||||||
redisClient.Set(strconv.Itoa(sent.MessageID), &CrispMessageInfo{
|
redisClient.Set(strconv.Itoa(sent.MessageID), &CrispMessageInfo{
|
||||||
WebsiteID,
|
WebsiteID,
|
||||||
SessionID,
|
SessionID,
|
||||||
}, 12*time.Hour)
|
}, 12*time.Hour)
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func main() {
|
||||||
config = utils.GetConfig()
|
config = utils.GetConfig()
|
||||||
|
|
||||||
var chat_prefix = config.GetString("prefix")
|
var chat_prefix = config.GetString("prefix")
|
||||||
|
|
||||||
log.Printf("Initializing Redis...")
|
log.Printf("Initializing Redis...")
|
||||||
|
/*
|
||||||
redisClient = redis.NewClient(&redis.Options{
|
redisClient = redis.NewClient(&redis.Options{
|
||||||
Addr: config.GetString("redis.host"),
|
Addr: config.GetString("redis.host"),
|
||||||
Password: config.GetString("redis.password"),
|
Password: config.GetString("redis.password"),
|
||||||
@ -113,7 +119,8 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
var err error
|
||||||
log.Printf("Initializing Bot...")
|
log.Printf("Initializing Bot...")
|
||||||
|
|
||||||
bot, err = tgbotapi.NewBotAPI(config.GetString("telegram.key"))
|
bot, err = tgbotapi.NewBotAPI(config.GetString("telegram.key"))
|
||||||
@ -171,12 +178,17 @@ func init() {
|
|||||||
log.Fatal("Crisp listener error, check your API key or internet connection?")
|
log.Fatal("Crisp listener error, check your API key or internet connection?")
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
for {
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func main() {
|
func main() {
|
||||||
var updates tgbotapi.UpdatesChannel
|
var updates tgbotapi.UpdatesChannel
|
||||||
|
|
||||||
log.Print("Start pooling")
|
log.Print("Start pooling")
|
||||||
|
|
||||||
u := tgbotapi.NewUpdate(0)
|
u := tgbotapi.NewUpdate(0)
|
||||||
u.Timeout = 60
|
u.Timeout = 60
|
||||||
|
|
||||||
@ -199,5 +211,7 @@ func main() {
|
|||||||
if contains(config.Get("admins").([]interface{}), int64(update.Message.From.ID)) {
|
if contains(config.Get("admins").([]interface{}), int64(update.Message.From.ID)) {
|
||||||
// replyToUser(&update)
|
// replyToUser(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user