whatsapp

package
v0.0.0-...-c4f7e29 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

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 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  *http.Client
	Endpoint    *url.URL
	Credentials *config.WhatsappOnPremisesCredentials
	TokenStore  *TokenStore
}

func NewWhatsappOnPremisesClient

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

func (*OnPremisesClient) GetOTPTemplate

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

func (*OnPremisesClient) SendTemplate

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

type PreparedOTPTemplate

type PreparedOTPTemplate struct {
	TemplateName string
	TemplateType string
	Language     string
	Components   []TemplateComponent
	Namespace    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 SendTemplateOptions

type SendTemplateOptions struct {
	TemplateName string
	To           string
	TemplateType string
	Language     string
	Components   []TemplateComponent
	Namespace    string
}

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 {
	Context                           context.Context
	Logger                            ServiceLogger
	DevMode                           config.DevMode
	FeatureTestModeWhatsappSuppressed config.FeatureTestModeWhatsappSuppressed
	TestModeWhatsappConfig            *config.TestModeWhatsappConfig
	WhatsappConfig                    *config.WhatsappConfig
	LocalizationConfig                *config.LocalizationConfig
	OnPremisesClient                  *OnPremisesClient
	TokenStore                        *TokenStore
}

func (*Service) PrepareOTPTemplate

func (s *Service) PrepareOTPTemplate(language string, text string, code string) (*PreparedOTPTemplate, error)

func (*Service) ResolveOTPTemplateLanguage

func (s *Service) ResolveOTPTemplateLanguage() (lang string, err error)

func (*Service) SendTemplate

func (s *Service) SendTemplate(opts *SendTemplateOptions) 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(endpoint string, username string) (*UserToken, error)

func (*TokenStore) Set

func (s *TokenStore) Set(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