Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- type FnOption
- func WithAPIToken(apiToken string) FnOption
- func WithBaseURL(baseURL string) FnOption
- func WithClient(client heimdall.Doer) FnOption
- func WithFromPhoneNumber(fromPhoneNumber string) FnOption
- func WithHystrixOptions(options []hystrix.Option) FnOption
- func WithNameSpace(nameSpace string) FnOption
- func WithTimeout(timeout time.Duration) FnOption
- type Option
- type RequestData
- type RequestFrom
- type RequestLanguage
- type RequestMessageTemplate
- type RequestRichTemplateData
- type RequestRichTmplBody
- type RequestRichTmplHeader
- type RequestRichTmplParams
- type RequestWhatsappMessage
- func (r *RequestWhatsappMessage) AddDestination(phoneNumber string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) Default(o *Option) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetDestinations(phoneNumbers []string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetFrom(from string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetHeaderMediaURL(url string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetHeaderParams(params []string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetHeaderType(headerType string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetLanguageCode(code string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetLanguagePolicy(policy string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetNamespace(ns string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetParams(params []string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetProvider(provider string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetStorage(storage string) *RequestWhatsappMessage
- func (r *RequestWhatsappMessage) SetTemplateName(tmpl string) *RequestWhatsappMessage
- type ResponseFailed
- type ResponseFreshchat
- type ResponseSuccess
- type ResponseSuccessLink
Constants ¶
const ( // DefaultBaseURLAustralia is the default base URL for the Freshchat API in Australia. DefaultBaseURLAustralia = "https://api.au.freshchat.com" // DefaultTimeout is the default timeout for the client. DefaultTimeout = 30 * time.Second )
const ( // DefaultProviderWhatsapp is the default provider for sending messages in the Freshchat. DefaultProviderWhatsapp = "whatsapp" // DefaultStorage is the default storage for sending messages. DefaultStorage = "none" // DefaultLanguagePolicy is the default language policy for sending messages. DefaultLanguagePolicy = "deterministic" // DefaultLanguageCode is the default language code for sending messages. DefaultLanguageCode = "id" )
const ( // TypePhoneSender is the type for phone sender. TypePhoneSender = "sender" // TypePhoneDestination is the type for phone destination. TypePhoneDestination = "destination" )
const (
// EndpointSendMessage is the endpoint for sending a message.
EndpointSendMessage = "/v2/outbound-messages/whatsapp"
)
const (
// HeaderBearerPrefix is the prefix for the Bearer token.
HeaderBearerPrefix = "Bearer "
)
Variables ¶
var ( // ErrNilArguments is returned when the arguments are nil. ErrNilArguments = errors.New("nil arguments") )
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v1.0.0
type Client interface {
SendMessage(ctx context.Context, req *RequestWhatsappMessage) (res *ResponseFreshchat, err error)
}
Client is the client for sending messages in the Freshchat.
type FnOption ¶ added in v1.0.0
type FnOption func(o *Option)
FnOption is a functional option for the Freshchat API
func WithAPIToken ¶ added in v1.0.2
WithAPIToken sets the API token for the Freshchat API.
func WithBaseURL ¶ added in v1.0.0
WithBaseURL sets the base URL for the Freshchat API.
func WithClient ¶ added in v1.0.0
func WithClient(client heimdall.Doer) FnOption
WithClient sets the client for the Freshchat API.
func WithFromPhoneNumber ¶ added in v1.0.0
WithFromPhoneNumber sets the from phone number for the Freshchat API.
func WithHystrixOptions ¶ added in v1.0.0
WithHystrixOptions sets the hystrix options for the Freshchat API.
func WithNameSpace ¶ added in v1.0.0
WithNameSpace sets the name space for the Freshchat API.
func WithTimeout ¶ added in v1.0.0
WithTimeout sets the timeout for the Freshchat API.
type Option ¶ added in v1.0.0
type Option struct { BaseURL string NameSpace string APIToken string FromPhoneNumber string Timeout time.Duration Client heimdall.Doer HystrixOptions []hystrix.Option // contains filtered or unexported fields }
Option is an option for the Freshchat API
type RequestData ¶ added in v1.0.0
type RequestData struct {
MessageTemplate RequestMessageTemplate `json:"message_template"`
}
RequestData is a request for specifying the message data.
func (*RequestData) Default ¶ added in v1.0.0
func (r *RequestData) Default(o *Option) *RequestData
Default is a default for RequestData.
type RequestFrom ¶ added in v1.0.0
type RequestFrom struct {
PhoneNumber string `json:"phone_number"`
}
RequestFrom is a request for specifying the sender number.
func (*RequestFrom) Default ¶ added in v1.0.0
func (r *RequestFrom) Default(o *Option, typePhone string) *RequestFrom
Default is a default for RequestFrom.
type RequestLanguage ¶ added in v1.0.0
RequestLanguage is a request for specifying the language.
func (*RequestLanguage) Default ¶ added in v1.0.0
func (r *RequestLanguage) Default(o *Option) *RequestLanguage
Default is a default for RequestLanguage.
type RequestMessageTemplate ¶ added in v1.0.0
type RequestMessageTemplate struct { Storage string `json:"storage"` TemplateName string `json:"template_name"` Namespace string `json:"namespace"` Language RequestLanguage `json:"language"` RichTemplateData RequestRichTemplateData `json:"rich_template_data"` }
RequestMessageTemplate is a request for specifying the message template.
func (*RequestMessageTemplate) Default ¶ added in v1.0.0
func (r *RequestMessageTemplate) Default(o *Option) *RequestMessageTemplate
Default is a default for RequestMessageTemplate.
type RequestRichTemplateData ¶ added in v1.0.0
type RequestRichTemplateData struct { Header *RequestRichTmplHeader `json:"header,omitempty"` Body RequestRichTmplBody `json:"body"` }
RequestRichTemplateData is a request for specifying the rich template data.
type RequestRichTmplBody ¶ added in v1.0.0
type RequestRichTmplBody struct {
Params []RequestRichTmplParams `json:"params"`
}
RequestRichTmplBody is a request for specifying the rich template body.
type RequestRichTmplHeader ¶ added in v1.0.0
type RequestRichTmplHeader struct { Type string `json:"type,omitempty"` MediaURL string `json:"media_url,omitempty"` Params []RequestRichTmplParams `json:"params,omitempty"` }
RequestRichTmplHeader is a request for specifying the rich template header.
type RequestRichTmplParams ¶ added in v1.0.0
type RequestRichTmplParams struct {
Data string `json:"data"`
}
RequestRichTmplParams is a request for specifying the rich template params data.
type RequestWhatsappMessage ¶ added in v1.0.0
type RequestWhatsappMessage struct { From RequestFrom `json:"from"` Provider string `json:"provider"` To []*RequestFrom `json:"to"` Data RequestData `json:"data"` // Response Attributes Below MessageID string `json:"message_id,omitempty"` RequestID string `json:"request_id,omitempty"` Status string `json:"status,omitempty"` FailureCode string `json:"failure_code,omitempty"` FailureReason string `json:"failure_reason,omitempty"` CreatedOn int `json:"created_on,omitempty"` }
RequestWhatsappMessage is a request for sending a message to a user.
func (*RequestWhatsappMessage) AddDestination ¶ added in v1.0.0
func (r *RequestWhatsappMessage) AddDestination(phoneNumber string) *RequestWhatsappMessage
AddDestination adds the destination for the message.
func (*RequestWhatsappMessage) Default ¶ added in v1.0.0
func (r *RequestWhatsappMessage) Default(o *Option) *RequestWhatsappMessage
Default is a default for RequestWhatsappMessage.
func (*RequestWhatsappMessage) SetDestinations ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetDestinations(phoneNumbers []string) *RequestWhatsappMessage
SetDestinations sets the destinations for the message.
func (*RequestWhatsappMessage) SetFrom ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetFrom(from string) *RequestWhatsappMessage
SetFrom sets the from/sender for the message.
func (*RequestWhatsappMessage) SetHeaderMediaURL ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetHeaderMediaURL(url string) *RequestWhatsappMessage
SetHeaderMediaURL sets the header media URL for the message.
func (*RequestWhatsappMessage) SetHeaderParams ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetHeaderParams(params []string) *RequestWhatsappMessage
SetHeaderParams sets the header params for the message.
func (*RequestWhatsappMessage) SetHeaderType ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetHeaderType(headerType string) *RequestWhatsappMessage
SetHeaderType sets the header type for the message.
func (*RequestWhatsappMessage) SetLanguageCode ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetLanguageCode(code string) *RequestWhatsappMessage
SetLanguageCode sets the language code for the message.
func (*RequestWhatsappMessage) SetLanguagePolicy ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetLanguagePolicy(policy string) *RequestWhatsappMessage
SetLanguagePolicy sets the language policy for the message.
func (*RequestWhatsappMessage) SetNamespace ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetNamespace(ns string) *RequestWhatsappMessage
SetNamespace sets the namespace for the message.
func (*RequestWhatsappMessage) SetParams ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetParams(params []string) *RequestWhatsappMessage
SetParams sets the params for the message.
func (*RequestWhatsappMessage) SetProvider ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetProvider(provider string) *RequestWhatsappMessage
SetProvider sets the provider for the message.
func (*RequestWhatsappMessage) SetStorage ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetStorage(storage string) *RequestWhatsappMessage
SetStorage sets the storage for the message.
func (*RequestWhatsappMessage) SetTemplateName ¶ added in v1.0.0
func (r *RequestWhatsappMessage) SetTemplateName(tmpl string) *RequestWhatsappMessage
SetTemplateName sets the template name for the message.
type ResponseFailed ¶ added in v1.0.0
type ResponseFailed struct { Success bool `json:"success"` ErrorCode int `json:"error_code"` ErrorMessage string `json:"error_message"` }
ResponseFailed is the failed response from Freshchat.
func (*ResponseFailed) Error ¶ added in v1.0.0
func (r *ResponseFailed) Error() string
Error implements the error interface.
type ResponseFreshchat ¶ added in v1.0.0
type ResponseFreshchat struct { Success *ResponseSuccess `json:"-"` Failed *ResponseFailed `json:"-"` HTTPStatusCode int `json:"-"` RawData string `json:"-"` }
ResponseFreshchat is the response from Freshchat.
type ResponseSuccess ¶ added in v1.0.0
type ResponseSuccess struct { RequestID string `json:"request_id"` RequestProcessTime string `json:"request_process_time"` Link ResponseSuccessLink `json:"link"` }
ResponseSuccess is the success response from Freshchat.
type ResponseSuccessLink ¶ added in v1.0.0
type ResponseSuccessLink struct { Href string `json:"href"` Rel string `json:"rel"` Type string `json:"type"` }
ResponseSuccessLink is the success link response from Freshchat.