v1

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 15 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// TemplateItemTypeText is a type for text chunk in template.
	TemplateItemTypeText uint8 = iota
	// TemplateItemTypeVar is a type for variable in template.
	TemplateItemTypeVar
)
View Source
const (
	// TemplateVarCustom is a custom variable type.
	TemplateVarCustom = "custom"
	// TemplateVarName is a name variable type.
	TemplateVarName = "name"
	// TemplateVarFirstName is a first name variable type.
	TemplateVarFirstName = "first_name"
	// TemplateVarLastName is a last name variable type.
	TemplateVarLastName = "last_name"
)
View Source
const (
	// ChannelFeatureNone channel can not implement feature.
	ChannelFeatureNone string = "none"
	// ChannelFeatureReceive channel implement feature on receive.
	ChannelFeatureReceive string = "receive"
	// ChannelFeatureSend channel implement feature on send.
	ChannelFeatureSend string = "send"
	// ChannelFeatureBoth channel implement feature on both directions.
	ChannelFeatureBoth string = "both"
	// ChannelFeatureAny channel implement feature on any.
	ChannelFeatureAny string = "any"
	// ChannelFeatureSendingPolicyNo channel can not implement feature.
	ChannelFeatureSendingPolicyNo string = "no"
	// ChannelFeatureSendingPolicyTemplate channel can implement template.
	ChannelFeatureSendingPolicyTemplate string = "template"
	// ChannelFeatureCustomerExternalIDPhone customer externalId is phone.
	ChannelFeatureCustomerExternalIDPhone string = "phone"

	// MsgTypeText text message.
	MsgTypeText string = "text"
	// MsgTypeSystem system message.
	MsgTypeSystem string = "system"
	// MsgTypeCommand command (for bots).
	MsgTypeCommand string = "command"
	// MsgTypeOrder order card.
	MsgTypeOrder string = "order"
	// MsgTypeProduct product card.
	MsgTypeProduct string = "product"
	// MsgTypeFile file card.
	MsgTypeFile string = "file"
	// MsgTypeImage image card.
	MsgTypeImage string = "image"
	// MsgTypeAudio audio.
	MsgTypeAudio string = "audio"

	// MsgOrderStatusCodeNew order status group new.
	MsgOrderStatusCodeNew = "new"
	// MsgOrderStatusCodeApproval order status group approval.
	MsgOrderStatusCodeApproval = "approval"
	// MsgOrderStatusCodeAssembling order status group assembling.
	MsgOrderStatusCodeAssembling = "assembling"
	// MsgOrderStatusCodeDelivery order status group delivery.
	MsgOrderStatusCodeDelivery = "delivery"
	// MsgOrderStatusCodeComplete order status group complete.
	MsgOrderStatusCodeComplete = "complete"
	// MsgOrderStatusCodeCancel order status group cancel.
	MsgOrderStatusCodeCancel = "cancel"

	FileSizeLimit = 20 * 1024 * 1024
)

noinspection ALL.

View Source
const LimitResponse = 25 * MB
View Source
const MB = 1 << 20
View Source
const TemplateTypeText = "text"

TemplateTypeText is a text template type. There is no other types for now.

Variables

View Source
var ErrInvalidOriginator = errors.New("invalid originator")

Functions

func BoolPtr added in v1.2.2

func BoolPtr(v bool) *bool

func MakeTimestamp added in v1.1.1

func MakeTimestamp() int64

MakeTimestamp returns current unix timestamp.

func NewAPIClientError added in v1.2.0

func NewAPIClientError(responseBody []byte) error

func NewCriticalHTTPError added in v1.2.0

func NewCriticalHTTPError(err error) error

func NewServerError added in v1.2.0

func NewServerError(response *http.Response) error

func OriginatorMarshalJSONInvalid added in v1.1.35

func OriginatorMarshalJSONInvalid(t *testing.T)

func TimePtr added in v1.2.2

func TimePtr(v time.Time) *time.Time

Types

type AckMessageRequest added in v1.1.41

type AckMessageRequest struct {
	ExternalMessageID  string            `json:"external_message_id"`
	TransportMessageID string            `json:"transport_message_id,omitempty"`
	Channel            uint64            `json:"channel"`
	Error              *MessageSentError `json:"error,omitempty"`
}

AckMessageRequest type.

type ActivateResponse

type ActivateResponse struct {
	ChannelID   uint64    `json:"id"`
	ExternalID  string    `json:"external_id"`
	ActivatedAt time.Time `json:"activated_at"`
}

ActivateResponse channel activation response.

type ActivateTemplateRequest added in v1.1.35

type ActivateTemplateRequest struct {
	Code     string         `binding:"required,min=1,max=512" json:"code"`
	Name     string         `binding:"required,min=1,max=512" json:"name"`
	Type     string         `binding:"required" json:"type"`
	Template []TemplateItem `json:"template"`
	Lang     string         `json:"lang,omitempty"`
	Category string         `json:"category,omitempty"`
}

type Attachments added in v1.1.40

type Attachments struct {
	Suggestions []Suggestion `json:"suggestions,omitempty"`
}

type BasicLogger added in v1.1.45

type BasicLogger interface {
	Printf(string, ...interface{})
}

BasicLogger provides basic functionality for logging.

func DebugLoggerAdapter added in v1.1.45

func DebugLoggerAdapter(logger DebugLogger) BasicLogger

DebugLoggerAdapter returns BasicLogger that calls underlying DebugLogger.Debugf.

type ButtonParam added in v1.2.7

type ButtonParam struct {
	ButtonType   ButtonType `json:"type"`
	Text         string     `json:"text,omitempty"`
	URLParameter string     `json:"urlParameter,omitempty"`
}

type ButtonType added in v1.2.7

type ButtonType string
const (
	QuickReplyButton  ButtonType = "QUICK_REPLY"
	PhoneNumberButton ButtonType = "PHONE_NUMBER"
	URLButton         ButtonType = "URL"
)

type Channel

type Channel struct {
	ID         uint64          `json:"id,omitempty"`
	ExternalID string          `json:"external_id,omitempty"`
	Type       string          `json:"type,omitempty"`
	Name       string          `json:"name,omitempty"`
	AvatarUrl  string          `json:"avatar_url,omitempty"`
	Settings   ChannelSettings `json:"settings,omitempty"`
}

Channel type.

type ChannelListItem added in v1.1.12

type ChannelListItem struct {
	ID            uint64          `json:"id"`
	ExternalID    string          `json:"external_id"`
	Type          string          `json:"type"`
	Name          *string         `json:"name"`
	Settings      ChannelSettings `json:"settings"`
	CreatedAt     string          `json:"created_at"`
	UpdatedAt     *string         `json:"updated_at"`
	ActivatedAt   string          `json:"activated_at"`
	DeactivatedAt *string         `json:"deactivated_at"`
	IsActive      bool            `json:"is_active"`
}

ChannelListItem response struct.

type ChannelSettings added in v1.1.1

type ChannelSettings struct {
	Status             Status                     `json:"status"`
	Text               ChannelSettingsText        `json:"text"`
	Product            Product                    `json:"product"`
	Order              Order                      `json:"order"`
	File               ChannelSettingsFilesBase   `json:"file"`
	Image              ChannelSettingsFilesBase   `json:"image"`
	CustomerExternalID string                     `json:"customer_external_id,omitempty"`
	SendingPolicy      SendingPolicy              `json:"sending_policy,omitempty"`
	Suggestions        ChannelSettingsSuggestions `json:"suggestions,omitempty"`
	Audio              ChannelSettingsAudio       `json:"audio"`
	Template           ChannelSettingsTemplate    `json:"template"`
}

ChannelSettings struct.

type ChannelSettingsAudio added in v1.1.47

type ChannelSettingsAudio struct {
	Creating      string  `json:"creating,omitempty"`
	Quoting       string  `json:"quoting,omitempty"`
	Deleting      string  `json:"deleting,omitempty"`
	MaxItemsCount uint64  `json:"max_items_count,omitempty"`
	MaxItemSize   *uint64 `json:"max_item_size,omitempty"`
}

ChannelSettingsAudio struct.

type ChannelSettingsFilesBase added in v1.1.15

type ChannelSettingsFilesBase struct {
	Creating          string  `json:"creating,omitempty"`
	Editing           string  `json:"editing,omitempty"`
	Quoting           string  `json:"quoting,omitempty"`
	Deleting          string  `json:"deleting,omitempty"`
	Max               uint64  `json:"max_items_count,omitempty"`
	NoteMaxCharsCount *uint16 `json:"note_max_chars_count,omitempty"`
	MaxItemSize       *uint64 `json:"max_item_size,omitempty"`
}

ChannelSettingsFilesBase struct.

type ChannelSettingsSuggestions added in v1.1.40

type ChannelSettingsSuggestions struct {
	Text  string `json:"text,omitempty"`
	Phone string `json:"phone,omitempty"`
	Email string `json:"email,omitempty"`
}

type ChannelSettingsTemplate added in v1.3.2

type ChannelSettingsTemplate struct {
	Creation bool `json:"creation,omitempty"`
}

type ChannelSettingsText added in v1.1.2

type ChannelSettingsText struct {
	Creating      string `json:"creating,omitempty"`
	Editing       string `json:"editing,omitempty"`
	Quoting       string `json:"quoting,omitempty"`
	Deleting      string `json:"deleting,omitempty"`
	MaxCharsCount uint16 `json:"max_chars_count,omitempty"`
}

ChannelSettingsText struct.

type Channels added in v1.1.12

type Channels struct {
	ID          int       `url:"id,omitempty" json:"id,omitempty"`
	Types       []string  `url:"types,omitempty" json:"types,omitempty"`
	Active      bool      `url:"active,omitempty" json:"active,omitempty"`
	Since       time.Time `url:"since,omitempty" json:"since,omitempty"`
	Until       time.Time `url:"until,omitempty" json:"until,omitempty"`
	TransportID uint64    `url:"transport_id,omitempty" json:"transport_id,omitempty"`
	Sort        string    `url:"sort,omitempty" json:"sort,omitempty"`
	Limit       int       `url:"limit,omitempty" json:"limit,omitempty"`
}

Channels request type.

type Customer added in v1.1.28

type Customer struct {
	ExternalID string `json:"external_id"`
	Nickname   string `json:"nickname"`
	Firstname  string `json:"first_name,omitempty"`
	Lastname   string `json:"last_name,omitempty"`
	Avatar     string `json:"avatar,omitempty"`
	ProfileURL string `json:"profile_url,omitempty"`
	Country    string `json:"country,omitempty"`
	Language   string `json:"language,omitempty"`
	Phone      string `json:"phone,omitempty"`
	Email      string `json:"email,omitempty"`
	Utm        *Utm   `json:"utm,omitempty"`
}

Customer struct.

type DebugLogger added in v1.1.45

type DebugLogger interface {
	Debugf(string, ...interface{})
}

DebugLogger can be used to easily wrap any logger with Debugf method into the BasicLogger instance.

type DeleteData added in v1.0.1

type DeleteData struct {
	Message Message `json:"message"`
	Channel uint64  `json:"channel"`
}

DeleteData struct.

type DeleteResponse

type DeleteResponse struct {
	ChannelID     uint64    `json:"id"`
	DeactivatedAt time.Time `json:"deactivated_at"`
}

DeleteResponse channel deactivation response.

type EditMessageRequest added in v1.1.13

type EditMessageRequest struct {
	Message EditMessageRequestMessage `json:"message"`
	Channel uint64                    `json:"channel"`
}

EditMessageRequest type.

type EditMessageRequestMessage added in v1.1.13

type EditMessageRequestMessage struct {
	ExternalID string `json:"external_id"`
	Text       string `json:"text"`
	EditedAt   int64  `json:"edited_at"`
}

EditMessageRequestMessage type.

type ErrorType added in v1.1.41

type ErrorType string
const (
	GeneralError           ErrorType = "general"
	CustomerNotExistsError ErrorType = "customer_not_exists"
	ReplyTimedOutError     ErrorType = "reply_timed_out"
	SpamSuspicionError     ErrorType = "spam_suspicion"
	AccessRestrictedError  ErrorType = "access_restricted"
)

type FileItem added in v1.1.15

type FileItem struct {
	ID      string `json:"id"`
	Size    int    `json:"size"`
	Caption string `json:"caption"`
	Height  *int   `json:"height,omitempty"`
	Width   *int   `json:"width,omitempty"`
}

FileItem struct.

type FileMeta added in v1.1.15

type FileMeta struct {
	Width  *int `json:"width,omitempty"`
	Height *int `json:"height,omitempty"`
}

FileMeta file metadata.

type FullFileResponse added in v1.1.15

type FullFileResponse struct {
	ID       string `json:"id,omitempty"`
	Type     string `json:"type,omitempty"`
	Size     int    `json:"size,omitempty"`
	Url      string `json:"url,omitempty"` //nolint:golint
	MimeType string `json:"mime_type,omitempty"`
}

FullFileResponse uploaded file data.

type HTTPClientError added in v1.2.0

type HTTPClientError struct {
	ErrorMsg  string
	BaseError error
	Response  io.Reader
}

func (*HTTPClientError) Error added in v1.2.0

func (err *HTTPClientError) Error() string

func (*HTTPClientError) Unwrap added in v1.2.0

func (err *HTTPClientError) Unwrap() error

type HeaderParams added in v1.2.7

type HeaderParams struct {
	TextVars    []string `json:"textVars,omitempty"`
	ImageURL    string   `json:"imageUrl,omitempty"`
	VideoURL    string   `json:"videoUrl,omitempty"`
	DocumentURL string   `json:"documentUrl,omitempty"`
}

type Item added in v1.1.15

type Item struct {
	ID      string `json:"id"`
	Caption string `json:"caption"`
}

Item struct.

type MGErrors added in v1.2.0

type MGErrors struct {
	Errors []string
}

type MarkMessageReadRequest added in v1.1.13

type MarkMessageReadRequest struct {
	Message   MarkMessageReadRequestMessage `json:"message"`
	ChannelID uint64                        `json:"channel_id"`
}

MarkMessageReadRequest type.

type MarkMessageReadRequestMessage added in v1.1.13

type MarkMessageReadRequestMessage struct {
	ExternalID string `json:"external_id"`
}

MarkMessageReadRequestMessage type.

type MarkMessageReadResponse added in v1.1.13

type MarkMessageReadResponse struct{}

MarkMessageReadResponse type.

type MarkMessagesReadUntilRequest added in v1.2.1

type MarkMessagesReadUntilRequest struct {
	CustomerExternalID string    `json:"customer_external_id"`
	ChannelID          uint64    `json:"channel_id"`
	Until              time.Time `json:"until"`
}

MarkMessagesReadUntilRequest type.

type MarkMessagesReadUntilResponse added in v1.2.1

type MarkMessagesReadUntilResponse struct {
	IDs []int64 `json:"ids"`
}

MarkMessagesReadUntilResponse type.

type Message

type Message struct {
	ExternalID string `json:"external_id"`
	Type       string `json:"type,omitempty"`
	Text       string `json:"text,omitempty"`
	Note       string `json:"note,omitempty"`
	Items      []Item `json:"items,omitempty"`
}

Message struct.

type MessageDataBot added in v1.1.3

type MessageDataBot struct {
	Name   string `json:"name"`
	Avatar string `json:"avatar"`
}

MessageDataBot bot data from webhook.

type MessageDataOrder added in v1.1.6

type MessageDataOrder struct {
	Number   string                    `json:"number"`
	Url      string                    `json:"url,omitempty"`
	Date     string                    `json:"date,omitempty"`
	Cost     *MessageDataOrderCost     `json:"cost,omitempty"`
	Discount *MessageDataOrderCost     `json:"discount,omitempty"`
	Status   *MessageDataOrderStatus   `json:"status,omitempty"`
	Delivery *MessageDataOrderDelivery `json:"delivery"`
	Payments []MessageDataOrderPayment `json:"payments"`
	Items    []MessageDataOrderItem    `json:"items,omitempty"`
}

MessageDataOrder order data from webhook.

type MessageDataOrderCost added in v1.1.6

type MessageDataOrderCost struct {
	Value    float32 `json:"value,omitempty"`
	Currency string  `json:"currency"`
}

MessageDataOrderCost type.

type MessageDataOrderDelivery added in v1.1.10

type MessageDataOrderDelivery struct {
	Name    string                `json:"name"`
	Price   *MessageDataOrderCost `json:"price"`
	Address string                `json:"address"`
	Comment string                `json:"comment,omitempty"`
}

MessageDataOrderDelivery type.

type MessageDataOrderItem added in v1.1.6

type MessageDataOrderItem struct {
	Name     string                    `json:"name,omitempty"`
	Url      string                    `json:"url,omitempty"`
	Img      string                    `json:"img,omitempty"`
	Quantity *MessageDataOrderQuantity `json:"quantity,omitempty"`
	Price    *MessageDataOrderCost     `json:"price,omitempty"`
}

MessageDataOrderItem type.

type MessageDataOrderPayment added in v1.1.10

type MessageDataOrderPayment struct {
	Name   string                         `json:"name"`
	Status *MessageDataOrderPaymentStatus `json:"status"`
	Amount *MessageDataOrderCost          `json:"amount"`
}

MessageDataOrderPayment type.

type MessageDataOrderPaymentStatus added in v1.1.10

type MessageDataOrderPaymentStatus struct {
	Name string `json:"name"`
	Paid bool   `json:"paid"`
}

MessageDataOrderPaymentStatus type.

type MessageDataOrderQuantity added in v1.1.6

type MessageDataOrderQuantity struct {
	Value float32 `json:"value"`
	Unit  string  `json:"unit"`
}

MessageDataOrderQuantity type.

type MessageDataOrderStatus added in v1.1.6

type MessageDataOrderStatus struct {
	Code string `json:"code,omitempty"`
	Name string `json:"name,omitempty"`
}

MessageDataOrderStatus type.

type MessageDataProduct added in v1.1.6

type MessageDataProduct struct {
	ID      uint64                `json:"id"`
	Name    string                `json:"name"`
	Article string                `json:"article,omitempty"`
	Url     string                `json:"url,omitempty"`
	Img     string                `json:"img,omitempty"`
	Cost    *MessageDataOrderCost `json:"cost,omitempty"`
	Unit    string                `json:"unit,omitempty"`
	// Deprecated: now you need to use Unit instead of this field
	Quantity *MessageDataOrderQuantity `json:"quantity,omitempty"`
}

MessageDataProduct product data from webhook.

type MessageDataUser added in v1.1.3

type MessageDataUser struct {
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Avatar    string `json:"avatar"`
}

MessageDataUser user data from webhook.

type MessageSentError added in v1.1.41

type MessageSentError struct {
	Code    ErrorType `json:"code"`
	Message string    `json:"message"`
}

MessageSentError type.

type MessageWebhookData added in v1.3.0

type MessageWebhookData struct {
	ExternalUserID    string              `json:"external_user_id"`
	ExternalMessageID string              `json:"external_message_id,omitempty"`
	ExternalChatID    string              `json:"external_chat_id"`
	ChannelID         uint64              `json:"channel_id"`
	Content           string              `json:"content"`
	QuoteExternalID   string              `json:"quote_external_id,omitempty"`
	QuoteContent      string              `json:"quote_content,omitempty"`
	Type              string              `json:"type"`
	User              *MessageDataUser    `json:"user,omitempty"`
	Bot               *MessageDataBot     `json:"bot,omitempty"`
	Product           *MessageDataProduct `json:"product,omitempty"`
	Order             *MessageDataOrder   `json:"order,omitempty"`
	Items             *[]FileItem         `json:"items,omitempty"`
	Template          *TemplateInfo       `json:"template,omitempty"`
	Attachments       *Attachments        `json:"attachments,omitempty"`
	InAppID           int32               `json:"in_app_id,omitempty"`
}

MessageWebhookData request data.

type MessagesResponse

type MessagesResponse struct {
	MessageID int       `json:"message_id,omitempty"`
	Time      time.Time `json:"time,omitempty"`
	Warnings  []string  `json:"warnings"`
}

MessagesResponse message event response.

type MgClient

type MgClient struct {
	URL   string `json:"url"`
	Token string `json:"token"`
	Debug bool   `json:"debug"`
	// contains filtered or unexported fields
}

MgClient type.

func New

func New(url string, token string) *MgClient

New initialize client.

func NewWithClient added in v1.1.33

func NewWithClient(url string, token string, client *http.Client) *MgClient

NewWithClient initializes client with provided http client.

func (*MgClient) AckMessage added in v1.1.41

func (c *MgClient) AckMessage(request AckMessageRequest) (int, error)

AckMessage implements ack of message

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

request := AckMessageRequest{
	ExternalMessageID: "274628",
	Channel: 10,
}

status, err := client.AckMessage(request)

if err != nil {
	fmt.Printf("%v", err)
}

func (*MgClient) ActivateTemplate added in v1.1.35

func (c *MgClient) ActivateTemplate(channelID uint64, request ActivateTemplateRequest) (int, error)

ActivateTemplate implements template activation

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

request := v1.ActivateTemplateRequest{
		Code: "code",
		Name: "name",
		Type: v1.TemplateTypeText,
		Template: []v1.TemplateItem{
			{
				Type: v1.TemplateItemTypeText,
				Text: "Hello, ",
			},
			{
				Type:    v1.TemplateItemTypeVar,
				VarType: v1.TemplateVarName,
			},
			{
				Type: v1.TemplateItemTypeText,
				Text: "!",
			},
		},
}

_, err := client.ActivateTemplate(uint64(1), request)

if err != nil {
	fmt.Printf("%v", err)
}

func (*MgClient) ActivateTransportChannel

func (c *MgClient) ActivateTransportChannel(request Channel) (ActivateResponse, int, error)

ActivateTransportChannel implement channel activation

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

request := ActivateRequest{
	Type: "telegram",
	Name: "@my_shopping_bot",
	Settings: ChannelSettings{
		Status: Status{
			Delivered: ChannelFeatureNone,
			Read: ChannelFeatureReceive,
		},
		Text: ChannelSettingsText{
			Creating: ChannelFeatureBoth,
			Editing:  ChannelFeatureBoth,
			Quoting:  ChannelFeatureReceive,
			Deleting: ChannelFeatureSend,
			MaxCharsCount: 2000,
		},
		Product: Product{
			Creating: ChannelFeatureSend,
			Deleting: ChannelFeatureSend,
		},
		Order: Order{
			Creating: ChannelFeatureBoth,
			Deleting: ChannelFeatureSend,
		},
	},
}

data, status, err := client.ActivateTransportChannel(request)

if err != nil {
	fmt.Printf("%v", err)
}

fmt.Printf("%s\n", data.CreatedAt)

func (*MgClient) DeactivateTemplate added in v1.1.35

func (c *MgClient) DeactivateTemplate(channelID uint64, templateCode string) (int, error)

DeactivateTemplate implements template deactivation

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

_, err := client.DeactivateTemplate(3053450384, "templateCode")

if err != nil {
	fmt.Printf("%v", err)
}

func (*MgClient) DeactivateTransportChannel

func (c *MgClient) DeactivateTransportChannel(id uint64) (DeleteResponse, int, error)

DeactivateTransportChannel implement channel deactivation

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

data, status, err := client.DeactivateTransportChannel(3053450384)

if err != nil {
	fmt.Printf("%v", err)
}

fmt.Printf("%s\n", data.DeactivatedAt)

func (*MgClient) DeleteMessage

func (c *MgClient) DeleteMessage(request DeleteData) (*MessagesResponse, int, error)

DeleteMessage implement delete message

Example:

	var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

	msg := DeleteData{
		Message{
			ExternalID: "274628",
		},
		10,
	}

	previousChatMessage, status, err := client.DeleteMessage(msg)
	if err != nil {
		fmt.Printf("%v", err)
	}

 if previousChatMessage != nil {
 	fmt.Printf("Previous chat message id = %d", previousChatMessage.MessageID)
 }

func (*MgClient) DeleteRequest

func (c *MgClient) DeleteRequest(url string, parameters []byte) ([]byte, int, error)

DeleteRequest implements DELETE Request.

func (*MgClient) GetFile added in v1.1.15

func (c *MgClient) GetFile(request string) (FullFileResponse, int, error)

GetFile implement get file url

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

data, status, err := client.GetFile("file_ID")

if err != nil {
	fmt.Printf("%v", err)
}

fmt.Printf("%s\n", data.MessageID)

func (*MgClient) GetRequest

func (c *MgClient) GetRequest(url string, parameters []byte) ([]byte, int, error)

GetRequest implements GET Request.

func (*MgClient) MarkMessageRead added in v1.1.13

func (c *MgClient) MarkMessageRead(request MarkMessageReadRequest) (MarkMessageReadResponse, int, error)

MarkMessageRead send message read event to MG

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")
msg := MarkMessageReadRequest{
	Message{
		ExternalID: "274628",
	},
	10,
}

data, status, err := client.MarkMessageRead(msg)

if err != nil {
	fmt.Printf("%v", err)
}

fmt.Printf("%v %v\n", status, data)

func (*MgClient) Messages

func (c *MgClient) Messages(request SendData) (MessagesResponse, int, error)

Messages implement send message

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")
msg := SendData{
	SendMessage{
		Message{
			ExternalID: "274628",
			Type:       "text",
			Text:       "hello!",
		},
		time.Now(),
	},
	User{
		ExternalID: "8",
		Nickname:   "@octopus",
		Firstname:  "Joe",
	},
	10,
}

data, status, err := client.Messages(msg)

if err != nil {
	fmt.Printf("%v", err)
}

fmt.Printf("%s\n", data.MessageID)

func (*MgClient) MessagesHistory added in v1.2.2

func (c *MgClient) MessagesHistory(request SendHistoryMessageRequest) (MessagesResponse, int, error)

MessagesHistory implement history message sending.

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")
msg := v1.SendHistoryMessageRequest{
	Message: v1.SendMessageRequestMessage{
		Type:       v1.MsgTypeText,
		ExternalID: "external_id",
		CreatedAt:  v1.TimePtr(time.Now()),
		IsComment:  false,
		Text:       "Test message",
	},
	ChannelID:      1,
	ExternalChatID: "chat_id",
	Customer: &v1.Customer{
		ExternalID: "1",
		Nickname:   "@john_doe",
		Firstname:  "John",
		Lastname:   "Doe",
	},
	Originator:    v1.OriginatorCustomer,
	ReplyDeadline: v1.TimePtr(time.Now().Add(time.Hour * 24)),
}

data, status, err := client.MessagesHistory(msg)
if err != nil {
	fmt.Printf("[%d]: %v", status, err)
}

fmt.Printf("%d\n", data.MessageID)

func (*MgClient) PostRequest

func (c *MgClient) PostRequest(url string, parameters io.Reader) ([]byte, int, error)

PostRequest implements POST Request.

func (*MgClient) PutRequest

func (c *MgClient) PutRequest(url string, parameters []byte) ([]byte, int, error)

PutRequest implements PUT Request.

func (*MgClient) ReadUntil added in v1.2.1

ReadUntil will mark all messages from specified timestamp as read.

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

request := ReadUntilRequest{
	ExternalMessageID: "274628",
	Channel: 10,
}

resp, status, err := client.ReadUntil(request)
if err != nil {
	fmt.Printf("%v", err)
}
if resp != nil {
	fmt.Printf("Marked these as read: %s", resp.IDs)
}

func (*MgClient) TransportChannels added in v1.1.12

func (c *MgClient) TransportChannels(request Channels) ([]ChannelListItem, int, error)

TransportChannels returns channels list

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

data, status, err := client.TransportChannels(Channels{Active: true})

if err != nil {
	fmt.Printf("%v", err)
}

fmt.Printf("Status: %v, Channels found: %v", status, len(data))

func (*MgClient) TransportTemplates added in v1.1.35

func (c *MgClient) TransportTemplates() ([]Template, int, error)

TransportTemplates returns templates list

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

data, status, err := client.TransportTemplates()

if err != nil {
	fmt.Printf("%v", err)
}

fmt.Printf("Status: %v, Templates found: %v", status, len(data))

func (*MgClient) UpdateMessages

func (c *MgClient) UpdateMessages(request EditMessageRequest) (MessagesResponse, int, error)

UpdateMessages implement edit message

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")
msg := UpdateData{
	UpdateMessage{
		Message{
			ExternalID: "274628",
			Type:       "text",
			Text:       "hello hello!",
		},
		MakeTimestamp(),
	},
	10,
}

data, status, err := client.UpdateMessages(msg)

if err != nil {
	fmt.Printf("%v", err)
}

fmt.Printf("%s\n", data.MessageID)

func (*MgClient) UpdateTemplate added in v1.1.35

func (c *MgClient) UpdateTemplate(request Template) (int, error)

UpdateTemplate implements template updating Example:

var client = New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

request := v1.Template{
	Code:      "templateCode",
	ChannelID: 1,
	Name:      "templateName",
	Template:  []v1.TemplateItem{
		{
			Type: v1.TemplateItemTypeText,
			Text: "Welcome, ",
		},
		{
			Type: v1.TemplateItemTypeVar,
			VarType: v1.TemplateVarName,
		},
		{
			Type: v1.TemplateItemTypeText,
			Text: "!",
		},
	},
}

_, err := client.UpdateTemplate(request)

if err != nil {
	fmt.Printf("%#v", err)
}

func (*MgClient) UpdateTransportChannel

func (c *MgClient) UpdateTransportChannel(request Channel) (UpdateResponse, int, error)

UpdateTransportChannel implement channel activation

Example:

var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")

request := ActivateRequest{
	ID:   3053450384,
	Type: "telegram",
	Name: "@my_shopping_bot",
	Settings: ChannelSettings{
		Status: Status{
			Delivered: ChannelFeatureNone,
			Read: ChannelFeatureReceive,
		},
		Text: ChannelSettingsText{
			Creating: ChannelFeatureBoth,
			Editing:  ChannelFeatureSend,
			Quoting:  ChannelFeatureReceive,
			Deleting: ChannelFeatureBoth,
		},
		Product: Product{
			Creating: ChannelFeatureSend,
			Deleting: ChannelFeatureSend,
		},
		Order: Order{
			Creating: ChannelFeatureBoth,
			Deleting: ChannelFeatureSend,
		},
	},
}

data, status, err := client.UpdateTransportChannel(request)

if err != nil {
	fmt.Printf("%v", err)
}

fmt.Printf("%s\n", data.UpdatedAt)

func (*MgClient) UploadFile added in v1.1.15

func (c *MgClient) UploadFile(request io.Reader) (UploadFileResponse, int, error)

UploadFile upload file.

func (*MgClient) UploadFileByURL added in v1.1.15

func (c *MgClient) UploadFileByURL(request UploadFileByUrlRequest) (UploadFileResponse, int, error)

UploadFileByURL upload file by url.

func (*MgClient) WithLogger added in v1.1.45

func (c *MgClient) WithLogger(logger BasicLogger) *MgClient

WithLogger sets the provided logger instance into the Client

type Order added in v1.1.8

type Order struct {
	Creating string `json:"creating,omitempty"`
	Editing  string `json:"editing,omitempty"`
	Deleting string `json:"deleting,omitempty"`
}

Order type.

type Originator added in v1.1.28

type Originator byte

Originator of message.

const (
	// OriginatorCustomer means message was created by customer.
	OriginatorCustomer Originator = iota + 1
	// OriginatorChannel means message was created by channel, for example via messenger mobile application.
	OriginatorChannel
)

func (Originator) MarshalText added in v1.1.28

func (o Originator) MarshalText() ([]byte, error)

MarshalText marshals originator to text.

func (*Originator) UnmarshalText added in v1.1.46

func (o *Originator) UnmarshalText(text []byte) error

UnmarshalText unmarshals originator from text to the value.

type Product added in v1.1.8

type Product struct {
	Creating string `json:"creating,omitempty"`
	Editing  string `json:"editing,omitempty"`
	Deleting string `json:"deleting,omitempty"`
}

Product type.

type SendData

type SendData struct {
	Message        Message                  `json:"message"`
	Originator     Originator               `json:"originator,omitempty"`
	Customer       Customer                 `json:"customer"`
	Channel        uint64                   `json:"channel"`
	ExternalChatID string                   `json:"external_chat_id"`
	Quote          *SendMessageRequestQuote `json:"quote,omitempty"`
	ReplyDeadline  *time.Time               `json:"reply_deadline,omitempty"`
}

SendData struct.

type SendHistoryMessageRequest added in v1.2.2

type SendHistoryMessageRequest struct {
	Message        SendMessageRequestMessage `json:"message"`
	ChannelID      uint64                    `json:"channel_id"`
	ExternalChatID string                    `json:"external_chat_id"`
	Customer       *Customer                 `json:"customer"`
	Quote          *SendMessageRequestQuote  `json:"quote,omitempty"`
	Originator     Originator                `json:"originator,omitempty"`
	ReplyDeadline  *time.Time                `json:"reply_deadline,omitempty"`
}

type SendMessage

type SendMessage struct {
	Message
	SentAt time.Time `json:"sent_at,omitempty"`
}

SendMessage struct.

type SendMessageRequestMessage added in v1.2.2

type SendMessageRequestMessage struct {
	Type       string     `json:"type"`
	ExternalID string     `json:"external_id,omitempty"`
	CreatedAt  *time.Time `json:"created_at,omitempty"`
	IsComment  bool       `json:"is_comment,omitempty"`
	Text       string     `json:"text"`
	Items      []Item     `json:"items"`
	Note       string     `json:"note,omitempty"`
}

type SendMessageRequestQuote added in v1.1.0

type SendMessageRequestQuote struct {
	ExternalID string `json:"external_id"`
}

SendMessageRequestQuote type.

type SendingPolicy added in v1.1.38

type SendingPolicy struct {
	NewCustomer       string `json:"new_customer,omitempty"`
	AfterReplyTimeout string `json:"after_reply_timeout,omitempty"`
	Outgoing          string `json:"outgoing,omitempty"`
}

type Status added in v1.1.2

type Status struct {
	Delivered string `json:"delivered,omitempty"`
	Read      string `json:"read,omitempty"`
}

Status struct.

type Suggestion added in v1.1.40

type Suggestion struct {
	Type  SuggestionType `json:"type"`
	Title string         `json:"title,omitempty"` // required for type=text and ignored for others
}

type SuggestionType added in v1.1.40

type SuggestionType string
const (
	SuggestionTypeText  SuggestionType = "text"
	SuggestionTypeEmail SuggestionType = "email"
	SuggestionTypePhone SuggestionType = "phone"
)

type Template added in v1.1.35

type Template struct {
	Code               string         `json:"code"`
	ChannelID          uint64         `json:"channel_id,omitempty"`
	Name               string         `json:"name"`
	Enabled            bool           `json:"enabled,omitempty"`
	Type               string         `json:"type"`
	Template           []TemplateItem `json:"template"`
	HeaderParams       *HeaderParams  `json:"headerParams,omitempty"`
	Footer             *string        `json:"footer,omitempty"`
	ButtonParams       []ButtonParam  `json:"buttonParams,omitempty"`
	Lang               string         `json:"lang,omitempty"`
	Category           string         `json:"category,omitempty"`
	RejectedReason     string         `json:"rejected_reason,omitempty"`
	VerificationStatus string         `json:"verification_status,omitempty"`
}

Template struct.

type TemplateContent added in v1.3.0

type TemplateContent struct {
	Name     string `json:"name"`
	Lang     string `json:"lang"`
	Category string `json:"category"`
	Body     string `json:"body"`
	Example  struct {
		Body []string `json:"body"`
	} `json:"example"`
}

type TemplateCreateWebhookData added in v1.3.0

type TemplateCreateWebhookData struct {
	TemplateContent
	ChannelID int64 `json:"channel_id"`
}

type TemplateCreateWebhookResponse added in v1.3.0

type TemplateCreateWebhookResponse struct {
	Code               string                     `json:"code" binding:"required"`
	VerificationStatus TemplateVerificationStatus `json:"verification_status" binding:"required"`
}

type TemplateDeleteWebhookData added in v1.3.0

type TemplateDeleteWebhookData struct {
	ChannelID int64  `json:"channel_id"`
	Code      string `json:"code"`
	Lang      string `json:"lang"`
}

type TemplateInfo added in v1.1.37

type TemplateInfo struct {
	Code         string        `json:"code"`
	Name         string        `json:"name"`
	Namespace    string        `json:"namespace"`
	Lang         string        `json:"lang"`
	HeaderParams *HeaderParams `json:"headerParams,omitempty"`
	Footer       string        `json:"footer,omitempty"`
	ButtonParams []ButtonParam `json:"buttonParams,omitempty"`
	Args         []string      `json:"args,omitempty"`
}

type TemplateItem added in v1.1.35

type TemplateItem struct {
	Type    uint8
	Text    string
	VarType string
}

TemplateItem is a part of template.

func (TemplateItem) MarshalJSON added in v1.1.35

func (t TemplateItem) MarshalJSON() ([]byte, error)

MarshalJSON controls how TemplateItem will be marshaled into JSON.

func (*TemplateItem) UnmarshalJSON added in v1.1.35

func (t *TemplateItem) UnmarshalJSON(b []byte) error

UnmarshalJSON will correctly unmarshal TemplateItem.

type TemplateUpdateWebhookData added in v1.3.0

type TemplateUpdateWebhookData struct {
	TemplateContent
	ChannelID int64  `json:"channel_id"`
	Code      string `json:"code"`
}

type TemplateVerificationStatus added in v1.3.0

type TemplateVerificationStatus string
const (
	TemplateStatusApproved TemplateVerificationStatus = "approved"
	TemplateStatusPending  TemplateVerificationStatus = "pending"
	TemplateStatusRejected TemplateVerificationStatus = "rejected"
	TemplateStatusNew      TemplateVerificationStatus = "new"
)

type TransportError added in v1.1.42

type TransportError struct {
	Code    TransportErrorCode `json:"code"`
	Message string             `json:"message,omitempty"`
}

type TransportErrorCode added in v1.1.42

type TransportErrorCode string
const (
	MessageErrorGeneral           TransportErrorCode = "general"
	MessageErrorCustomerNotExists TransportErrorCode = "customer_not_exists"
	MessageErrorReplyTimedOut     TransportErrorCode = "reply_timed_out"
	MessageErrorSpamSuspicion     TransportErrorCode = "spam_suspicion"
	MessageErrorAccessRestricted  TransportErrorCode = "access_restricted"
)

func (TransportErrorCode) MarshalJSON added in v1.1.42

func (t TransportErrorCode) MarshalJSON() ([]byte, error)

type TransportRequestMeta added in v1.1.0

type TransportRequestMeta struct {
	ID        uint64 `json:"id"`
	Timestamp int64  `json:"timestamp"`
}

TransportRequestMeta request metadata.

type TransportResponse added in v1.1.42

type TransportResponse struct {
	ExternalMessageID string          `json:"external_message_id,omitempty"`
	Error             *TransportError `json:"error,omitempty"`
}

func NewSentMessageResponse added in v1.1.42

func NewSentMessageResponse(externalMessageID string) TransportResponse

func NewTransportErrorResponse added in v1.1.42

func NewTransportErrorResponse(code TransportErrorCode, message string) TransportResponse

type UpdateResponse

type UpdateResponse struct {
	ChannelID  uint64    `json:"id"`
	ExternalID string    `json:"external_id"`
	UpdatedAt  time.Time `json:"updated_at"`
}

UpdateResponse channel update response.

type UploadFileByUrlRequest added in v1.1.15

type UploadFileByUrlRequest struct {
	Url string `json:"url"`
}

UploadFileByUrlRequest file url to upload.

type UploadFileResponse added in v1.1.15

type UploadFileResponse struct {
	ID        string    `json:"id"`
	Hash      string    `json:"hash"`
	Type      string    `json:"type"`
	Meta      FileMeta  `json:"meta"`
	MimeType  string    `json:"mime_type"`
	Size      int       `json:"size"`
	Url       *string   `json:"source_url"`
	CreatedAt time.Time `json:"created_at"`
}

UploadFileResponse uploaded file data.

type Utm added in v1.2.3

type Utm struct {
	Source   string `json:"source,omitempty"`
	Medium   string `json:"medium,omitempty"`
	Campaign string `json:"campaign,omitempty"`
	Term     string `json:"term,omitempty"`
	Content  string `json:"content,omitempty"`
}

type WebhookMessageSentResponse added in v1.1.41

type WebhookMessageSentResponse struct {
	ExternalMessageID string            `json:"external_message_id"`
	Error             *MessageSentError `json:"error,omitempty"`
	Async             bool              `json:"async"`
}

WebhookMessageSentResponse type Consider using this structure while processing webhook request.

type WebhookRequest added in v1.1.0

type WebhookRequest struct {
	Type WebhookType          `json:"type"`
	Meta TransportRequestMeta `json:"meta"`
	Data json.RawMessage      `json:"data"`
}

WebhookRequest type.

func (WebhookRequest) IsMessageWebhook added in v1.3.0

func (w WebhookRequest) IsMessageWebhook() bool

IsMessageWebhook returns true if current webhook contains data related to chat messages.

func (WebhookRequest) IsTemplateWebhook added in v1.3.0

func (w WebhookRequest) IsTemplateWebhook() bool

func (WebhookRequest) MessageWebhookData added in v1.3.0

func (w WebhookRequest) MessageWebhookData() (wd MessageWebhookData)

func (WebhookRequest) TemplateCreateWebhookData added in v1.3.0

func (w WebhookRequest) TemplateCreateWebhookData() (wd TemplateCreateWebhookData)

func (WebhookRequest) TemplateDeleteWebhookData added in v1.3.0

func (w WebhookRequest) TemplateDeleteWebhookData() (wd TemplateDeleteWebhookData)

func (WebhookRequest) TemplateUpdateWebhookData added in v1.3.0

func (w WebhookRequest) TemplateUpdateWebhookData() (wd TemplateUpdateWebhookData)

type WebhookType added in v1.3.0

type WebhookType string
const (
	MessageSendWebhookType    WebhookType = "message_sent"
	MessageUpdateWebhookType  WebhookType = "message_updated"
	MessageDeleteWebhookType  WebhookType = "message_deleted"
	MessageReadWebhookType    WebhookType = "message_read"
	TemplateCreateWebhookType WebhookType = "template_create"
	TemplateUpdateWebhookType WebhookType = "template_update"
	TemplateDeleteWebhookType WebhookType = "template_delete"
)

Jump to

Keyboard shortcuts

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