Commit 9e9a2058 by keith

update

parent ad0a0917
...@@ -4,16 +4,16 @@ import ( ...@@ -4,16 +4,16 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/validation"
"kefu_server/configs" "kefu_server/configs"
"kefu_server/im"
"kefu_server/models" "kefu_server/models"
robotlbrary "kefu_server/robot"
"kefu_server/services" "kefu_server/services"
"kefu_server/utils" "kefu_server/utils"
"strconv" "strconv"
"time" "time"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/validation"
) )
// MessageController struct // MessageController struct
...@@ -67,8 +67,8 @@ func (c *MessageController) List() { ...@@ -67,8 +67,8 @@ func (c *MessageController) List() {
} }
// push notify update current service contacts list // push notify update current service contacts list
if len(im.Robots) > 0 { if len(robotlbrary.Robots) > 0 {
im.PushNewContacts(auth.UID, im.Robots[0]) robotlbrary.PushNewContacts(auth.UID, robotlbrary.Robots[0])
} }
c.JSON(configs.ResponseSucess, "success", &returnMessagePaginationDto) c.JSON(configs.ResponseSucess, "success", &returnMessagePaginationDto)
...@@ -126,7 +126,7 @@ func (c *MessageController) Transfer() { ...@@ -126,7 +126,7 @@ func (c *MessageController) Transfer() {
} }
} }
robot := im.Robots[0] robot := robotlbrary.Robots[0]
robotID, _ := strconv.ParseInt(robot.AppAccount(), 10, 64) robotID, _ := strconv.ParseInt(robot.AppAccount(), 10, 64)
type adminData struct { type adminData struct {
......
...@@ -4,8 +4,8 @@ import ( ...@@ -4,8 +4,8 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"kefu_server/configs" "kefu_server/configs"
"kefu_server/im"
"kefu_server/models" "kefu_server/models"
robotlbrary "kefu_server/robot"
"kefu_server/services" "kefu_server/services"
"kefu_server/utils" "kefu_server/utils"
"os" "os"
...@@ -100,7 +100,7 @@ func (c *PublicController) Register() { ...@@ -100,7 +100,7 @@ func (c *PublicController) Register() {
if user != nil { if user != nil {
// fetchResult // fetchResult
fetchResult, fetchError = im.GetMiMcToken(strconv.FormatInt(user.ID, 10)) fetchResult, fetchError = robotlbrary.GetMiMcToken(strconv.FormatInt(user.ID, 10))
if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil { if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil {
c.JSON(configs.ResponseFail, "注册失败!", &err) c.JSON(configs.ResponseFail, "注册失败!", &err)
} }
...@@ -126,7 +126,7 @@ func (c *PublicController) Register() { ...@@ -126,7 +126,7 @@ func (c *PublicController) Register() {
if accountID, err := c.UserRepository.Add(user); err == nil { if accountID, err := c.UserRepository.Add(user); err == nil {
fetchResult, fetchError = im.GetMiMcToken(strconv.FormatInt(accountID, 10)) fetchResult, fetchError = robotlbrary.GetMiMcToken(strconv.FormatInt(accountID, 10))
if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil { if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil {
c.JSON(configs.ResponseFail, "注册失败!", &err) c.JSON(configs.ResponseFail, "注册失败!", &err)
} }
...@@ -149,7 +149,7 @@ func (c *PublicController) Register() { ...@@ -149,7 +149,7 @@ func (c *PublicController) Register() {
admin = c.AdminRepository.GetAdmin(auth.UID) admin = c.AdminRepository.GetAdmin(auth.UID)
// fetchResult // fetchResult
fetchResult, fetchError = im.GetMiMcToken(strconv.FormatInt(admin.ID, 10)) fetchResult, fetchError = robotlbrary.GetMiMcToken(strconv.FormatInt(admin.ID, 10))
// imTokenDto // imTokenDto
if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil { if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil {
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"github.com/astaxie/beego/validation" "github.com/astaxie/beego/validation"
"kefu_server/configs" "kefu_server/configs"
"kefu_server/im"
"kefu_server/models" "kefu_server/models"
robotlbrary "kefu_server/robot"
"kefu_server/services" "kefu_server/services"
"strconv" "strconv"
"strings" "strings"
...@@ -81,7 +81,7 @@ func (c *RobotController) Delete() { ...@@ -81,7 +81,7 @@ func (c *RobotController) Delete() {
} }
// init robots // init robots
im.RobotInit() robotlbrary.RobotInit()
c.JSON(configs.ResponseSucess, "删除成功!", nil) c.JSON(configs.ResponseSucess, "删除成功!", nil)
} }
...@@ -134,7 +134,7 @@ func (c *RobotController) Post() { ...@@ -134,7 +134,7 @@ func (c *RobotController) Post() {
c.JSON(configs.ResponseFail, "添加失败!", nil) c.JSON(configs.ResponseFail, "添加失败!", nil)
} }
im.RobotInit() robotlbrary.RobotInit()
c.JSON(configs.ResponseSucess, "添加成功!", id) c.JSON(configs.ResponseSucess, "添加成功!", id)
} }
...@@ -217,7 +217,7 @@ func (c *RobotController) Put() { ...@@ -217,7 +217,7 @@ func (c *RobotController) Put() {
robot.Artificial = strings.Trim(robot.Artificial, "|") robot.Artificial = strings.Trim(robot.Artificial, "|")
robot.KeyWord = strings.Trim(robot.KeyWord, "|") robot.KeyWord = strings.Trim(robot.KeyWord, "|")
robot.CreateAt = oldRobot.CreateAt robot.CreateAt = oldRobot.CreateAt
im.RobotInit() robotlbrary.RobotInit()
c.JSON(configs.ResponseSucess, "修改成功!", &robot) c.JSON(configs.ResponseSucess, "修改成功!", &robot)
} }
......
package im package robotlbrary
import ( import (
"encoding/base64" "encoding/base64"
......
package im package robotlbrary
import ( import (
"container/list" "container/list"
...@@ -26,12 +26,31 @@ func (c MsgHandler) HandleMessage(packets *list.List) { ...@@ -26,12 +26,31 @@ func (c MsgHandler) HandleMessage(packets *list.List) {
// 收到的原始消息 // 收到的原始消息
p2pMsg := ele.Value.(*msg.P2PMessage) p2pMsg := ele.Value.(*msg.P2PMessage)
// 取出用户发的消息内容 // get message
var message models.Message var message models.Message
msgContent, _ := base64.StdEncoding.DecodeString(string(p2pMsg.Payload())) msgContentByte, err := base64.StdEncoding.DecodeString(string(p2pMsg.Payload()))
//logs.Info("收到消息", *p2pMsg.FromAccount(), *p2pMsg.ToAccount(), *p2pMsg.Timestamp(),*p2pMsg.PacketId(),*p2pMsg.Sequence()) err = json.Unmarshal(msgContentByte, &message)
_ = json.Unmarshal(msgContent, &message)
switch message.BizType {
// 消息入库
case "into":
return
// 撤销消息
case "cancel":
return
// 搜索知识库
case "search_knowledge":
return
// 与机器人握手
case "handshake":
return
default:
}
if err == nil {
MessageP2P(message) MessageP2P(message)
}
} }
......
package im package robotlbrary
import "github.com/astaxie/beego/logs" import "github.com/astaxie/beego/logs"
......
package im package robotlbrary
import ( import (
"bytes" "bytes"
......
package robotlbrary
func main() {
// robot run
RobotInit()
}
package im package robotlbrary
import ( import (
"encoding/base64" "encoding/base64"
...@@ -61,15 +61,11 @@ func MessageP2P(message models.Message) { ...@@ -61,15 +61,11 @@ func MessageP2P(message models.Message) {
break break
} }
} }
if isFromAccountRobot { if isFromAccountRobot {
return return
} }
// 判断机器人是否在线
if robot.Status() == 1 {
robot.Login()
}
// 是否是入库消息(中转入库) // 是否是入库消息(中转入库)
if message.BizType == "into" { if message.BizType == "into" {
var intoMessage models.Message var intoMessage models.Message
......
package im package robotlbrary
import ( import (
"bytes" "bytes"
......
package im package robotlbrary
import ( import (
"kefu_server/models" "kefu_server/models"
......
...@@ -3,7 +3,7 @@ package task ...@@ -3,7 +3,7 @@ package task
import ( import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"kefu_server/im" "kefu_server/robot"
"kefu_server/models" "kefu_server/models"
"kefu_server/utils" "kefu_server/utils"
"strconv" "strconv"
......
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 sign in to comment