Commit 9e9a2058 by keith

update

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