whatsapp

package
v0.0.0-...-f50e335 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	LoginResponseUserExpiresTimeLayout = "2006-01-02 15:04:05-07:00"
)

Variables

View Source
var ErrBadRequest = errors.New("whatsapp: bad request")
View Source
var ErrInvalidUser = errors.New("whatsapp: invalid user")
View Source
var ErrNoAvailableClient = errors.New("whatsapp: no available client")
View Source
var ErrUnauthorized = errors.New("whatsapp: unauthorized")
View Source
var ErrUnexpectedLoginResponse = errors.New("whatsapp: unexpected login response body")

Functions

This section is empty.

Types

type HTTPClient

type HTTPClient struct {
	*http.Client
}

func NewHTTPClient

func NewHTTPClient() HTTPClient

type LoginResponse

type LoginResponse struct {
	Users []LoginResponseUser `json:"users"`
}

type LoginResponseUser

type LoginResponseUser struct {
	Token        string                       `json:"token"`
	ExpiresAfter LoginResponseUserExpiresTime `json:"expires_after"`
}

type LoginResponseUserExpiresTime

type LoginResponseUserExpiresTime time.Time

func (LoginResponseUserExpiresTime) MarshalText

func (j LoginResponseUserExpiresTime) MarshalText() ([]byte, error)

func (*LoginResponseUserExpiresTime) UnmarshalText

func (j *LoginResponseUserExpiresTime) UnmarshalText(textb []byte) error

Implement Marshaler and Unmarshaler interface

type OnPremisesClient

type OnPremisesClient struct {
	HTTPClient  HTTPClient
	Endpoint    *url.URL
	Credentials *config.WhatsappOnPremisesCredentials
	TokenStore  *TokenStore
}

func NewWhatsappOnPremisesClient

func NewWhatsappOnPremisesClient(
	cfg *config.WhatsappConfig,
	credentials *config.WhatsappOnPremisesCredentials,
	tokenStore *TokenStore,
	httpClient HTTPClient,
) *OnPremisesClient

func (*OnPremisesClient) GetOTPTemplate

func (c *OnPremisesClient) GetOTPTemplate() *config.WhatsappTemplateConfig

func (*OnPremisesClient) SendTemplate

func (c *OnPremisesClient) SendTemplate(
	ctx context.Context,
	to string,
	templateName string,
	templateLanguage string,
	templateComponents []TemplateComponent,
	namespace string) error

type ResolvedSendAuthenticationOTPOptions

type ResolvedSendAuthenticationOTPOptions struct {
	To                 string
	OTP                string
	TemplateName       string
	TemplateLanguage   string
	TemplateNamespace  string
	TemplateComponents []TemplateComponent
}

type SendAuthenticationOTPOptions

type SendAuthenticationOTPOptions struct {
	To  string
	OTP string
}

type SendTemplateError

type SendTemplateError struct {
	Code    int    `json:"code"`
	Title   string `json:"title"`
	Details string `json:"details"`
}

type SendTemplateErrorResponse

type SendTemplateErrorResponse struct {
	Errors *[]SendTemplateError `json:"errors,omitempty"`
}

type SendTemplateRequest

type SendTemplateRequest struct {
	RecipientType string    `json:"recipient_type"`
	To            string    `json:"to"`
	Type          string    `json:"type"`
	Template      *Template `json:"template"`
}

type Service

type Service struct {
	Logger             ServiceLogger
	WhatsappConfig     *config.WhatsappConfig
	LocalizationConfig *config.LocalizationConfig
	OnPremisesClient   *OnPremisesClient
}

func (*Service) ResolveSendAuthenticationOTPOptions

func (s *Service) ResolveSendAuthenticationOTPOptions(ctx context.Context, opts *SendAuthenticationOTPOptions) (*ResolvedSendAuthenticationOTPOptions, error)

func (*Service) SendAuthenticationOTP

func (s *Service) SendAuthenticationOTP(ctx context.Context, opts *ResolvedSendAuthenticationOTPOptions) error

type ServiceLogger

type ServiceLogger struct{ *log.Logger }

func NewServiceLogger

func NewServiceLogger(lf *log.Factory) ServiceLogger

type Template

type Template struct {
	Name       string              `json:"name"`
	Language   *TemplateLanguage   `json:"language"`
	Components []TemplateComponent `json:"components"`
	Namespace  *string             `json:"namespace,omitempty"`
}

type TemplateComponent

type TemplateComponent struct {
	Type       TemplateComponentType        `json:"type"`
	SubType    *TemplateComponentSubType    `json:"sub_type,omitempty"`
	Index      *int                         `json:"index,omitempty"`
	Parameters []TemplateComponentParameter `json:"parameters"`
}

func NewTemplateButtonComponent

func NewTemplateButtonComponent(subtyp TemplateComponentSubType, index int) *TemplateComponent

func NewTemplateComponent

func NewTemplateComponent(typ TemplateComponentType) *TemplateComponent

type TemplateComponentParameter

type TemplateComponentParameter struct {
	Type TemplateComponentParameterType `json:"type"`
	Text string                         `json:"text"`
}

func NewTemplateComponentTextParameter

func NewTemplateComponentTextParameter(text string) *TemplateComponentParameter

type TemplateComponentParameterType

type TemplateComponentParameterType string
const (
	TemplateComponentParameterTypeText TemplateComponentParameterType = "text"
)

type TemplateComponentSubType

type TemplateComponentSubType string
const (
	TemplateComponentSubTypeURL TemplateComponentSubType = "url"
)

type TemplateComponentType

type TemplateComponentType string
const (
	TemplateComponentTypeHeader TemplateComponentType = "header"
	TemplateComponentTypeBody   TemplateComponentType = "body"
	TemplateComponentTypeButton TemplateComponentType = "button"
)

type TemplateLanguage

type TemplateLanguage struct {
	Policy string `json:"policy"`
	Code   string `json:"code"`
}

type TokenStore

type TokenStore struct {
	Redis *appredis.Handle
	AppID config.AppID
	Clock clock.Clock
}

func (*TokenStore) Get

func (s *TokenStore) Get(ctx context.Context, endpoint string, username string) (*UserToken, error)

func (*TokenStore) Set

func (s *TokenStore) Set(ctx context.Context, token *UserToken) error

type UserToken

type UserToken struct {
	Endpoint string    `json:"endpoint"`
	Username string    `json:"username"`
	Token    string    `json:"token"`
	ExpireAt time.Time `json:"expire_at"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL