BroadcastMessageOnChannel api 추가
This commit is contained in:
@ -2,6 +2,7 @@ package core
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
@ -97,6 +98,7 @@ func (gc *groupChat) Initialize(sub *subTavern, cfg configDocument) error {
|
||||
|
||||
sub.apiFuncs.registApiFunction("CreateChattingChannel", gc.CreateChattingChannel)
|
||||
sub.apiFuncs.registApiFunction("FetchChattingChannels", gc.FetchChattingChannels)
|
||||
sub.apiFuncs.registApiFunction("BroadcastMessageOnChannel", gc.BroadcastMessageOnChannel)
|
||||
|
||||
for name, cfg := range gc.chatConfig.Channels {
|
||||
if _, ok := cfg["capacity"]; !ok {
|
||||
@ -224,3 +226,15 @@ func (gc *groupChat) FetchChattingChannels(w http.ResponseWriter, r *http.Reques
|
||||
enc := json.NewEncoder(w)
|
||||
enc.Encode(channels)
|
||||
}
|
||||
|
||||
func (gc *groupChat) BroadcastMessageOnChannel(w http.ResponseWriter, r *http.Request) {
|
||||
nickname, _ := gocommon.ReadStringFormValue(r.Form, "nickname")
|
||||
channel, _ := gocommon.ReadStringFormValue(r.Form, "channel")
|
||||
text, _ := io.ReadAll(r.Body)
|
||||
|
||||
gc.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||
Target: "#" + channel,
|
||||
Body: map[string]any{"sender": nickname, "msg": string(text)},
|
||||
Tag: []string{"TextMessage"},
|
||||
})
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.20
|
||||
require (
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
go.mongodb.org/mongo-driver v1.11.7
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230801051747-b501160efc3b
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230802072134-f6441a9b4c53
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
2
go.sum
2
go.sum
@ -106,3 +106,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230801051747-b501160efc3b h1:yV1cBeu0GFxkDD6TDxzKv/rM3OMtyt1JXpeqDF5IO3Y=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230801051747-b501160efc3b/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230802072134-f6441a9b4c53 h1:E3wNjCk4ztgrkSiU6NUvn0Ss7CN0bpkAKKINfpIniS4=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230802072134-f6441a9b4c53/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
||||
|
||||
Reference in New Issue
Block a user