You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

callback.go 3.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright © 2023 OpenIM open source community. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package api
  15. import (
  16. "fmt"
  17. "net/http"
  18. "github.com/gin-gonic/gin"
  19. "github.com/openimsdk/openkf/server/internal/common"
  20. "github.com/openimsdk/openkf/server/internal/common/response"
  21. slackcmd "github.com/openimsdk/openkf/server/internal/msg/slack_cmd"
  22. requestparams "github.com/openimsdk/openkf/server/internal/params/request"
  23. "github.com/openimsdk/openkf/server/internal/service"
  24. "github.com/openimsdk/openkf/server/pkg/log"
  25. )
  26. // OpenIMCallback
  27. // @Tags openim
  28. // @Summary OpenIMCallback
  29. // @Description Support OpenIM callback
  30. // @Produce application/json
  31. // @Success 200 {object} response.Response{msg=string} "Success"
  32. // @Router /api/v1/openim/callback [post].
  33. func OpenIMCallback(c *gin.Context) {
  34. param := &requestparams.OpenIMCallbackCommand{}
  35. err := c.ShouldBindQuery(param)
  36. if err != nil {
  37. // todo
  38. response.FailWithCode(common.INVALID_PARAMS, c)
  39. return
  40. }
  41. // redirect to the corresponding router
  42. callbackURL := fmt.Sprintf("%s%s", c.Request.URL.Path, param.Command)
  43. c.Request.URL.Path = callbackURL
  44. c.Redirect(http.StatusTemporaryRedirect, callbackURL)
  45. }
  46. // BeforeSendSingleMsg.
  47. func BeforeSendSingleMsg(c *gin.Context) {
  48. // Msg filter
  49. params := &requestparams.MsgAbstract{}
  50. err := c.ShouldBindJSON(params)
  51. if err != nil {
  52. // Do not check
  53. return
  54. }
  55. // Send message to slack user
  56. ssvc := service.NewUserDispatchService(c)
  57. if check := ssvc.SlackUserFilter(params.RecvID); check {
  58. log.Debugf("Msg filter", "Send message to slack: %s", params.RecvID)
  59. slackcmd.SendMsg(params)
  60. }
  61. }
  62. // AfterSendSingleMsg.
  63. func AfterSendSingleMsg(c *gin.Context) {
  64. log.Infof("UserOnline", "UserOnline")
  65. params := &requestparams.MsgAbstract{}
  66. err := c.ShouldBindJSON(params)
  67. if err != nil {
  68. // Do not check
  69. return
  70. }
  71. // Save to influxdb
  72. svc := service.NewIMCallbackService(c)
  73. if err := svc.AfterSendSingleMsgCallback(params.SendID, params.Content); err != nil {
  74. log.Errorf("AfterSendSingleMsg", "Write to influx db error: %s", err.Error())
  75. return
  76. }
  77. }
  78. // UserOnline.
  79. func UserOnline(c *gin.Context) {
  80. log.Infof("UserOnline", "UserOnline")
  81. params := &requestparams.CallbackUserOnlineReq{}
  82. err := c.ShouldBindJSON(params)
  83. if err != nil {
  84. // Do not check
  85. return
  86. }
  87. // Save to influxdb
  88. svc := service.NewIMCallbackService(c)
  89. if err := svc.UserOnlineCallback(params.UserID); err != nil {
  90. log.Errorf("UserOnline", "Write to influx db error: %s", err.Error())
  91. return
  92. }
  93. }
  94. // UserOffline.
  95. func UserOffline(c *gin.Context) {
  96. log.Infof("UserOffline", "UserOffline")
  97. params := &requestparams.CallbackUserOfflineReq{}
  98. err := c.ShouldBindJSON(params)
  99. if err != nil {
  100. // Do not check
  101. return
  102. }
  103. // Save to influxdb
  104. svc := service.NewIMCallbackService(c)
  105. if err := svc.UserOfflineCallback(params.UserID); err != nil {
  106. log.Errorf("UserOffline", "Write to influx db error: %s", err.Error())
  107. return
  108. }
  109. }
  110. // MsgModify.
  111. func MsgModify(c *gin.Context) {
  112. }
  113. // OfflinePush.
  114. func OfflinePush(c *gin.Context) {
  115. }
  116. // OnlinePush.
  117. func OnlinePush(c *gin.Context) {
  118. }