Skip to content

Commit

Permalink
chore: Wip
Browse files Browse the repository at this point in the history
Signed-off-by: sarthakjdev <[email protected]>
  • Loading branch information
sarthakjdev committed May 28, 2024
1 parent 841b7b8 commit 2ae7b38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 4 additions & 6 deletions internal/manager/webhook_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@ func (wh *WebhookManager) createEchoHttpServer() *echo.Echo {

}

func (wh *WebhookManager) getRequestHandler(c echo.Context) {

func (wh *WebhookManager) GetRequestHandler(c echo.Context) {
// this endpoint is used to verify the webhook

request := c.Request()
fmt.Println(request)

}

func (wh *WebhookManager) postRequestHandler(c echo.Context) {
func (wh *WebhookManager) PostRequestHandler(c echo.Context) {
// emits events based on the payload of the request

request := c.Request()
Expand All @@ -82,12 +80,12 @@ func (wh *WebhookManager) ListenToEvents() {
server := wh.createEchoHttpServer()

server.GET(wh.path, func(c echo.Context) error {
wh.getRequestHandler(c)
wh.GetRequestHandler(c)
return c.String(200, "ok")
})

server.POST(wh.path, func(c echo.Context) error {
wh.postRequestHandler(c)
wh.PostRequestHandler(c)
return c.String(200, "ok")
})

Expand Down
9 changes: 9 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wapi
import (
"fmt"

"github.com/labstack/echo/v4"
"github.com/sarthakjdev/wapi.go/internal/manager"
requestclient "github.com/sarthakjdev/wapi.go/internal/request_client"
"github.com/sarthakjdev/wapi.go/pkg/events"
Expand Down Expand Up @@ -67,6 +68,14 @@ func (client *Client) InitiateClient() bool {
return true
}

func (client *Client) GetWebhookGetRequestHandler() func(c echo.Context) {
return client.webhook.GetRequestHandler
}

func (client *Client) GetWebhookPostRequestHandler() func(c echo.Context) {
return client.webhook.PostRequestHandler
}

// OnMessage registers a handler for a specific event type.
func (client *Client) On(eventType manager.EventType, handler func(events.BaseEvent)) {
client.webhook.EventManager.On(eventType, handler)
Expand Down

0 comments on commit 2ae7b38

Please sign in to comment.