Documentation
¶
Index ¶
- Variables
- func VerifyWebhookSignature(appSecret string, body []byte, signatureHeader string) error
- type Client
- func (client *Client) GetWebhookGetRequestHandler() func(c echo.Context) error
- func (client *Client) GetWebhookPostRequestHandler() func(c echo.Context) error
- func (client *Client) Initiate() bool
- func (client *Client) NewMessagingClient(phoneNumberId string) *messaging.MessagingClient
- func (client *Client) On(eventType events.EventType, handler func(events.BaseEvent))
- type ClientConfig
- type GraphAPIError
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidWebhookSignature = manager.ErrInvalidWebhookSignature
ErrInvalidWebhookSignature is returned by VerifyWebhookSignature when the signature header is missing, malformed or does not match the body.
Functions ¶
func VerifyWebhookSignature ¶ added in v0.8.1
VerifyWebhookSignature checks a Meta X-Hub-Signature-256 header value ("sha256=<hex>") against the HMAC-SHA256 of the raw request body keyed with the app secret. It is what the webhook POST handler runs when ClientConfig.WebhookAppSecret is set, exposed for callers that verify signatures themselves.
Types ¶
type Client ¶
type Client struct {
Business business.BusinessClient // Business is the business client.
Messaging []messaging.MessagingClient // MessagingClient is the messaging client.
// contains filtered or unexported fields
}
func New ¶
func New(config *ClientConfig) *Client
func (*Client) GetWebhookGetRequestHandler ¶
GetWebhookGetRequestHandler returns the handler function for handling GET requests to the webhook.
func (*Client) GetWebhookPostRequestHandler ¶
GetWebhookPostRequestHandler returns the handler function for handling POST requests to the webhook.
func (*Client) Initiate ¶
InitiateClient initializes the client and starts listening to events from the webhook. It returns true if the client was successfully initiated.
func (*Client) NewMessagingClient ¶
func (client *Client) NewMessagingClient(phoneNumberId string) *messaging.MessagingClient
type ClientConfig ¶
type ClientConfig struct {
BusinessAccountId string
ApiAccessToken string
WebhookSecret string `validate:"required"`
// these two are not required, because may be user want to use their own server
WebhookPath string
WebhookServerPort int
// WebhookAppSecret is the Meta app secret. When set, the webhook POST
// handler rejects requests whose X-Hub-Signature-256 header does not match
// the raw body with 401. Leave it empty if a proxy in front of the handler
// verifies signatures itself or rewrites the body.
WebhookAppSecret string
// HTTPClient is used for every Graph API request. Defaults to a shared
// client with connect, TLS and response-header timeouts.
HTTPClient *http.Client
// ApiVersion is the Graph API version, e.g. "v21.0". Defaults to "v20.0".
ApiVersion string
// GraphBaseURL is the scheme and host of the Graph API. Defaults to
// "https://graph.facebook.com"; set it to an httptest server URL in tests.
GraphBaseURL string
}
type GraphAPIError ¶ added in v0.8.1
type GraphAPIError = request_client.GraphAPIError
GraphAPIError is the error returned for a non-2xx Graph API response. It carries the HTTP status, Meta's error code/subcode/message and the raw body.
Use AsGraphAPIError (or errors.As) to inspect it instead of matching on the error string:
if apiErr, ok := wapi.AsGraphAPIError(err); ok && apiErr.IsRetryable() { ... }
func AsGraphAPIError ¶ added in v0.8.1
func AsGraphAPIError(err error) (*GraphAPIError, bool)
AsGraphAPIError reports whether err is, or wraps, a *GraphAPIError and returns it.