BroadcastMessageOnChannel api 추가

This commit is contained in:
2023-08-02 16:22:18 +09:00
parent 12ddd2cbfb
commit 9de686e828
3 changed files with 17 additions and 1 deletions

View File

@ -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"},
})
}