add generic request
This commit is contained in:
parent
bf3d383615
commit
442aaf0056
3 changed files with 45 additions and 0 deletions
32
libmxclient/mxutils/generic.go
Normal file
32
libmxclient/mxutils/generic.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2026 saces@c-base.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
package mxutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
)
|
||||
|
||||
type req_data struct {
|
||||
Method string `json:"method"`
|
||||
Path mautrix.BaseURLPath `json:"path"`
|
||||
Payload any `json:"payload"`
|
||||
}
|
||||
|
||||
func GenericRequest(hs string, accessToken string, reqData string) (string, error) {
|
||||
var rd req_data
|
||||
err := json.Unmarshal([]byte(reqData), &rd)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
mauclient, err := mautrix.NewClient(hs, "", accessToken)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
urlPath := mauclient.BuildURLWithFullQuery(mautrix.BaseURLPath(rd.Path), nil)
|
||||
resp, err := mauclient.MakeRequest(context.Background(), rd.Method, urlPath, rd.Payload, nil)
|
||||
return string(resp), err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue