优化发信息

pull/23/head
630892807@qq.com 3 years ago
parent 900a349774
commit 4c08c54eaa

@ -162,21 +162,25 @@ func SendMessageV2(c *gin.Context) {
if guest != nil && ok {
ws.VisitorMessage(vistorInfo.VisitorId, content, kefuInfo)
}
msg = TypeMessage{
Type: "message",
Data: ws.ClientMessage{
Name: kefuInfo.Nickname,
Avator: kefuInfo.Avator,
Id: vistorInfo.VisitorId,
Time: time.Now().Format("2006-01-02 15:04:05"),
ToId: vistorInfo.VisitorId,
Content: content,
IsKefu: "yes",
},
}
str2, _ := json.Marshal(msg)
ws.OneKefuMessage(kefuInfo.Name, str2)
ws.KefuMessage(vistorInfo.VisitorId, content, kefuInfo)
//msg = TypeMessage{
// Type: "message",
// Data: ws.ClientMessage{
// Name: kefuInfo.Nickname,
// Avator: kefuInfo.Avator,
// Id: vistorInfo.VisitorId,
// Time: time.Now().Format("2006-01-02 15:04:05"),
// ToId: vistorInfo.VisitorId,
// Content: content,
// IsKefu: "yes",
// },
//}
//str2, _ := json.Marshal(msg)
//ws.OneKefuMessage(kefuInfo.Name, str2)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
})
}
if cType == "visitor" {
//kefuConns, ok := ws.KefuList[kefuInfo.Name]
@ -203,26 +207,19 @@ func SendMessageV2(c *gin.Context) {
ws.OneKefuMessage(kefuInfo.Name, str)
go ws.SendServerJiang(vistorInfo.Name+"说", content, c.Request.Host)
go SendAppGetuiPush(kefuInfo.Name, vistorInfo.Name, content)
go ws.VisitorAutoReply(vistorInfo, kefuInfo, content)
kefus, ok := ws.KefuList[kefuInfo.Name]
if !ok || len(kefus) == 0 {
log.Println("客服不在线,发送邮件通知")
go SendNoticeEmail(content+"|"+vistorInfo.Name, content)
}
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result": msg,
})
}
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result": msg,
})
kefus, ok := ws.KefuList[kefuInfo.Name]
if !ok || len(kefus) == 0 {
log.Println("客服不在线,发送邮件通知")
go SendNoticeEmail(content+"|"+vistorInfo.Name, content)
go func() {
time.Sleep(1 * time.Second)
welcome := models.FindWelcomeByUserIdKey(kefuInfo.Name, "offline")
if welcome.Content == "" {
return
}
ws.VisitorMessage(vistorInfo.VisitorId, welcome.Content, kefuInfo)
models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, welcome.Content, "kefu")
}()
}
}
func SendVisitorNotice(c *gin.Context) {
notice := c.Query("msg")

@ -14,6 +14,11 @@ type ReplyGroup struct {
Items []*ReplyItem `json:"items";"`
}
func FindReplyItemByUserIdTitle(userId interface{}, title string) ReplyItem {
var reply ReplyItem
DB.Where("user_id = ? and item_name = ?", userId, title).Find(&reply)
return reply
}
func FindReplyByUserId(userId interface{}) []*ReplyGroup {
var replyGroups []*ReplyGroup
//DB.Raw("select a.*,b.* from reply_group a left join reply_item b on a.id=b.group_id where a.user_id=? ", userId).Scan(&replyGroups)

@ -7,6 +7,7 @@ import (
"github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools"
"log"
"time"
)
func NewKefuServer(c *gin.Context) {
@ -102,6 +103,22 @@ func OneKefuMessage(toId string, str []byte) {
SuperAdminMessage(str)
}
func KefuMessage(visitorId, content string, kefuInfo models.User) {
msg := TypeMessage{
Type: "message",
Data: ClientMessage{
Name: kefuInfo.Nickname,
Avator: kefuInfo.Avator,
Id: visitorId,
Time: time.Now().Format("2006-01-02 15:04:05"),
ToId: visitorId,
Content: content,
IsKefu: "yes",
},
}
str, _ := json.Marshal(msg)
OneKefuMessage(kefuInfo.Name, str)
}
//给客服客户端发送消息判断客户端是否在线
func SendPingToKefuClient() {

@ -151,3 +151,22 @@ func VisitorMessage(visitorId, content string, kefuInfo models.User) {
visitor := ClientList[visitorId]
visitor.Conn.WriteMessage(websocket.TextMessage, str)
}
func VisitorAutoReply(vistorInfo models.Visitor, kefuInfo models.User, content string) {
kefus, ok := KefuList[kefuInfo.Name]
reply := models.FindReplyItemByUserIdTitle(kefuInfo.Name, content)
if reply.Content != "" {
time.Sleep(2 * time.Second)
VisitorMessage(vistorInfo.VisitorId, reply.Content, kefuInfo)
KefuMessage(vistorInfo.VisitorId, reply.Content, kefuInfo)
models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, reply.Content, "kefu")
}
if !ok || len(kefus) == 0 {
time.Sleep(1 * time.Second)
welcome := models.FindWelcomeByUserIdKey(kefuInfo.Name, "offline")
if welcome.Content == "" || reply.Content != "" {
return
}
VisitorMessage(vistorInfo.VisitorId, welcome.Content, kefuInfo)
models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, welcome.Content, "kefu")
}
}

Loading…
Cancel
Save