Commit 910763c4 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

update chat info

parent 6300183e
...@@ -78,6 +78,16 @@ func (m *Messenger) ExistGroupChat(userId, chatId int64) (exist bool, err error) ...@@ -78,6 +78,16 @@ func (m *Messenger) ExistGroupChat(userId, chatId int64) (exist bool, err error)
} }
} }
func (m *Messenger) GetChatInfo(chatId int) (title, name string, err error) {
chat, err := m.bot.GetChat(tgbotapi.ChatInfoConfig{ChatConfig: tgbotapi.ChatConfig{ChatID: int64(chatId)}})
if err != nil {
log.WithError(err).Error("get chat info error")
return
}
return chat.Title, chat.UserName, nil
}
func (m *Messenger) handleNewUser(msg *tgbotapi.Message) (caught bool) { func (m *Messenger) handleNewUser(msg *tgbotapi.Message) (caught bool) {
for _, user := range msg.NewChatMembers { for _, user := range msg.NewChatMembers {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
......
...@@ -8,7 +8,7 @@ func TestFunc(t *testing.T) { ...@@ -8,7 +8,7 @@ func TestFunc(t *testing.T) {
token := "6507972032:AAFAjaNz70ibA42kSH7k2gblyIQa1gWJiW0" token := "6507972032:AAFAjaNz70ibA42kSH7k2gblyIQa1gWJiW0"
m := NewMessenger(token, nil) m := NewMessenger(token, nil)
m.ExistGroupChat(6689160806, -1002174503961) // m.ExistGroupChat(6689160806, -1002174503961)
m.Start() m.GetChatInfo(-1002174503961)
} }
package server
import (
"sdk_api/constant"
"strconv"
"github.com/gin-gonic/gin"
)
func getChat(c *gin.Context) {
_chatId := c.Query("chatId")
chatId, _ := strconv.Atoi(_chatId)
if chatId == 0 {
c.JSON(200, withError(constant.InvalidParam))
return
}
title, username, err := srv.GetChatInfo(chatId)
if err != nil {
c.JSON(200, withError(constant.InternalError))
return
}
c.JSON(200, withSuccess(gin.H{"title": title, "username": username}))
}
...@@ -17,4 +17,6 @@ func initRouter(e *gin.Engine) { ...@@ -17,4 +17,6 @@ func initRouter(e *gin.Engine) {
user.GET("/active", active) user.GET("/active", active)
} }
v1.GET("/chat", getChat)
} }
package service
import (
log "github.com/sirupsen/logrus"
)
func (s *Service) GetChatInfo(chatId int) (title, name string, err error) {
title, name, err = s.msger.GetChatInfo(chatId)
if err != nil {
log.WithError(err).Error("get chat info error")
}
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment