Skip to content

Commit

Permalink
more debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
gempir committed Feb 18, 2024
1 parent b8d31aa commit be711ad
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NEXT_PUBLIC_API_BASE_URL="http://localhost:3010"
NEXT_PUBLIC_BASE_URL="http://localhost:3000"
NEXT_PUBLIC_TWITCH_CLIENT_ID="7ex2fcx0zjznrb3o20gl10f53ury1j"
WEBHOOK_API_BASE_URL="https://gempbot.bore.services"
WEBHOOK_API_BASE_URL="https://gempbot.loca.lt"
TWITCH_USERNAME="gempbot"
DSN="postgresql://postgres:postgres@localhost:5432"
LISTEN_ADDRESS="127.0.0.1:3010"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ run_docker:
docker run --env-file=.env -p 3010:3010 gempbot

tunnel:
bore -id gempbot -s bore.services -p 2200 -ls localhost -lp 3010
npx localtunnel --port 3010 --subdomain gempbot
57 changes: 41 additions & 16 deletions internal/helixclient/chat.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package helixclient

import (
"context"
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"

"github.com/carlmjohnson/requests"
"github.com/nicklaw5/helix/v2"
)

Expand All @@ -15,24 +18,46 @@ type SendChatMessageResponse struct {
}

func (c *HelixClient) SendChatMessage(channelID string, message string) (*SendChatMessageResponse, error) {
var resp SendChatMessageResponse

params := helix.SendChatMessageParams{
BroadcasterID: channelID,
Message: message,
SenderID: c.botUserID,
}

err := requests.
URL(TWITCH_API).
BodyJSON(params).
Bearer(c.AppAccessToken.AccessToken).
Header("Client-Id", c.clientID).
ContentType("application/json").
Path("/helix/chat/messages").
ToJSON(&resp).
Post().
Fetch(context.Background())

return &resp, err
jsonParams, err := json.Marshal(params)
if err != nil {
return nil, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/helix/chat/messages", TWITCH_API), bytes.NewBuffer(jsonParams))
if err != nil {
return nil, err
}

req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.AppAccessToken.AccessToken))
req.Header.Set("Client-Id", c.clientID)
req.Header.Set("Content-Type", "application/json")

resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

if resp.StatusCode >= 300 {
return nil, fmt.Errorf("[%d] %s", resp.StatusCode, string(body))
}

var msgs SendChatMessageResponse
err = json.Unmarshal(body, &msgs)
if err != nil {
return nil, err
}

return &msgs, nil
}

0 comments on commit be711ad

Please sign in to comment.