From 73168b73024f0599222c7f4e1959cee61c858e39 Mon Sep 17 00:00:00 2001 From: IRONICBo <47499836+IRONICBo@users.noreply.github.com> Date: Sun, 13 Aug 2023 11:47:46 +0800 Subject: [PATCH] fix: Split modules to client and cmd. Signed-off-by: IRONICBo <47499836+IRONICBo@users.noreply.github.com> --- server/internal/conn/client/slack.go | 37 ++++++++++++++++++++++++++ server/internal/msg/slack_cmd/slack.go | 15 +++++------ server/main.go | 2 +- 3 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 server/internal/conn/client/slack.go diff --git a/server/internal/conn/client/slack.go b/server/internal/conn/client/slack.go new file mode 100644 index 0000000..1bf15a2 --- /dev/null +++ b/server/internal/conn/client/slack.go @@ -0,0 +1,37 @@ +// Copyright © 2023 OpenIM open source community. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package client + +import ( + "github.com/shomali11/slacker" + + "github.com/OpenIMSDK/OpenKF/server/internal/config" + "github.com/OpenIMSDK/OpenKF/server/pkg/log" +) + +// SlackBot slack client. +var SlackBot *slacker.Slacker + +// InitSlack init slack client. +func InitSlack() *slacker.Slacker { + botToken := config.Config.Slack.BotToken + appToken := config.Config.Slack.AppToken + debug := config.Config.App.Debug + + SlackBot = slacker.NewClient(botToken, appToken, slacker.WithDebug(debug)) + log.Info("Slack", "init config ok") + + return SlackBot +} diff --git a/server/internal/msg/slack_cmd/slack.go b/server/internal/msg/slack_cmd/slack.go index afa6d5a..b276f50 100644 --- a/server/internal/msg/slack_cmd/slack.go +++ b/server/internal/msg/slack_cmd/slack.go @@ -20,21 +20,17 @@ import ( "github.com/shomali11/slacker" - "github.com/OpenIMSDK/OpenKF/server/internal/config" + "github.com/OpenIMSDK/OpenKF/server/internal/conn/client" "github.com/OpenIMSDK/OpenKF/server/internal/service" "github.com/OpenIMSDK/OpenKF/server/pkg/log" ) -// InitSlack init slack client. -func InitSlack() { - botToken := config.Config.Slack.BotToken - appToken := config.Config.Slack.AppToken - debug := config.Config.App.Debug +// InitSlackListen init slack socket listen. +func InitSlackListen() { + bot := client.InitSlack() svc := service.NewSlackService(context.Background()) - bot := slacker.NewClient(botToken, appToken, slacker.WithDebug(debug)) - // receive all @ message bot.Command("", &slacker.CommandDefinition{ Handler: func(bc slacker.BotContext, r slacker.Request, w slacker.ResponseWriter) { @@ -48,10 +44,11 @@ func InitSlack() { } question := r.Param("question") - // todo: remove id from question + // TODO: remove id from question words := strings.Split(question, " ") question = strings.Join(words[1:], " ") + // TODO: get staff id and get into im process. _ = senderId _ = question _ = w.Reply("senderId", slacker.WithThreadReply(true)) diff --git a/server/main.go b/server/main.go index c7d3923..a01b745 100644 --- a/server/main.go +++ b/server/main.go @@ -43,7 +43,7 @@ func init() { client.InitMinio() // client.InitMail() hooks.InitHooks() - slackcmd.InitSlack() + slackcmd.InitSlackListen() } //go:generate go env -w GO111MODULE=on