Documentation
¶
Overview ¶
Package conversation provides an interface to the Conversations API. The API's docs are located here: https://developers.messagebird.com/docs/conversations. The api.go file contains the structs returned by the API, and the other files provide the functionality needed to send requests, as well as any structs required for that - e.g. request data or pagination options.
Index ¶
- Variables
- func DeleteWebhook(c *messagebird.Client, id string) error
- type Audio
- type Channel
- type Contact
- type Conversation
- type ConversationList
- type ConversationStatus
- type File
- type HSM
- type HSMLanguage
- type HSMLanguagePolicy
- type HSMLocalizableParameter
- type HSMLocalizableParameterCurrency
- type Image
- type ListOptions
- type Location
- type Media
- type Message
- type MessageContent
- type MessageCreateRequest
- type MessageDirection
- type MessageList
- type MessageStatus
- type MessageType
- type MessagesCount
- type StartRequest
- type UpdateRequest
- type Video
- type Webhook
- type WebhookCreateRequest
- type WebhookEvent
- type WebhookList
- type WebhookStatus
- type WebhookUpdateRequest
Constants ¶
This section is empty.
Variables ¶
var DefaultListOptions = &ListOptions{10, 0}
DefaultListOptions provide a reasonable default for paginated endpoints.
Functions ¶
func DeleteWebhook ¶
func DeleteWebhook(c *messagebird.Client, id string) error
DeleteWebhook ensures an existing webhook is deleted and no longer triggered. If the error is nil, the deletion was successful.
Types ¶
type Contact ¶
type Contact struct { ID string Href string MSISDN string FirstName string LastName string CustomDetails map[string]interface{} CreatedAt *time.Time UpdatedAt *time.Time }
func (*Contact) UnmarshalJSON ¶
UnmarshalJSON is used to unmarshal the MSISDN to a string rather than an int64. The API returns integers, but this client always uses strings. Exposing a json.Number doesn't seem nice.
type Conversation ¶
type Conversation struct { ID string ContactID string Contact *Contact LastUsedChannelID string Channels []*Channel Messages *MessagesCount Status ConversationStatus CreatedDatetime time.Time UpdatedDatetime *time.Time LastReceivedDatetime *time.Time }
func Read ¶
func Read(c *messagebird.Client, id string) (*Conversation, error)
Read fetches a single Conversation based on its ID.
func Start ¶
func Start(c *messagebird.Client, req *StartRequest) (*Conversation, error)
Start creates a conversation by sending an initial message. If an active conversation exists for the recipient, it is resumed.
func Update ¶
func Update(c *messagebird.Client, id string, req *UpdateRequest) (*Conversation, error)
Update changes the conversation's status, so this can be used to (un)archive conversations.
type ConversationList ¶
type ConversationList struct { Offset int Limit int Count int TotalCount int Items []*Conversation }
func List ¶
func List(c *messagebird.Client, options *ListOptions) (*ConversationList, error)
List gets a collection of Conversations. Pagination can be set in options.
type ConversationStatus ¶
type ConversationStatus string
ConversationStatus indicates what state a Conversation is in.
const ( // ConversationStatusActive is returned when the Conversation is active. // Only one active conversation can ever exist for a given contact. ConversationStatusActive ConversationStatus = "active" // ConversationStatusArchived is returned when the Conversation is // archived. When this is the case, a new Conversation is created when a // message is received from a contact. ConversationStatusArchived ConversationStatus = "archived" )
type HSM ¶
type HSM struct { Namespace string `json:"namespace"` TemplateName string `json:"templateName"` Language *HSMLanguage `json:"language"` LocalizableParameters []*HSMLocalizableParameter `json:"params"` }
HSM is a pre-approved, reusable message template required when messaging over WhatsApp. It allows you to just send the required parameter values instead of the full message. It also allows for localization of the message and decreases the possibility of being blocked on the first contact as the message is pre-approved by WhatsApp.
type HSMLanguage ¶
type HSMLanguage struct { Policy HSMLanguagePolicy `json:"policy"` // Code can be both language and language_locale formats (e.g. en and // en_US). Code string `json:"code"` }
HSMLanguage is used to set the message's locale.
type HSMLanguagePolicy ¶
type HSMLanguagePolicy string
HSMLanguagePolicy sets how the provided language is enforced.
const ( // HSMLanguagePolicyFallback will deliver the message template in the // user's device language. If the settings can't be found on the user's // device the fallback language is used. HSMLanguagePolicyFallback HSMLanguagePolicy = "fallback" // HSMLanguagePolicyDeterministic will deliver the message template // exactly in the language and locale asked for. HSMLanguagePolicyDeterministic HSMLanguagePolicy = "deterministic" )
type HSMLocalizableParameter ¶
type HSMLocalizableParameter struct { Default string `json:"default"` Currency *HSMLocalizableParameterCurrency `json:"currency,omitempty"` DateTime *time.Time `json:"dateTime,omitempty"` }
HSMLocalizableParameter are used to replace the placeholders in the message template. They will be localized by WhatsApp. Default values are used when localization fails. Default is required. Additionally, currency OR DateTime may be present in a request.
func CurrencyLocalizableHSMParameter ¶
func CurrencyLocalizableHSMParameter(d string, code string, amount int64) *HSMLocalizableParameter
CurrencyLocalizableHSMParameter gets a parameter that localizes a currency. Code is the currency code in ISO 4217 format and amount is the total amount, including cents, multiplied by 1000. E.g. 12.34 becomes 12340.
func DateTimeLocalizableHSMParameter ¶
func DateTimeLocalizableHSMParameter(d string, dateTime time.Time) *HSMLocalizableParameter
DateTimeLocalizableHSMParameter gets a parameter that localizes a DateTime.
func DefaultLocalizableHSMParameter ¶
func DefaultLocalizableHSMParameter(d string) *HSMLocalizableParameter
DefaultLocalizableHSMParameter gets a simple parameter with a default value that will do a simple string replacement.
type ListOptions ¶
type ListOptions struct {
Limit, Offset int
}
ListOptions can be used to set pagination options in List().
type Message ¶
type Message struct { ID string ConversationID string ChannelID string Direction MessageDirection Status MessageStatus Type MessageType Content MessageContent CreatedDatetime *time.Time UpdatedDatetime *time.Time }
func CreateMessage ¶
func CreateMessage(c *messagebird.Client, conversationID string, req *MessageCreateRequest) (*Message, error)
CreateMessage sends a new message to the specified conversation. To create a new conversation and send an initial message, use conversation.Start().
func ReadMessage ¶
func ReadMessage(c *messagebird.Client, messageID string) (*Message, error)
ReadMessage gets a single message based on its ID.
type MessageContent ¶
type MessageContent struct { Audio *Audio `json:"audio,omitempty"` File *File `json:"file,omitempty"` Image *Image `json:"image,omitempty"` Location *Location `json:"location,omitempty"` Video *Video `json:"video,omitempty"` Text string `json:"text,omitempty"` // HSM is a highly structured message for WhatsApp. Its definition lives in // hsm.go. HSM *HSM `json:"hsm,omitempty"` }
MessageContent holds a message's actual content. Only one field can be set per request.
type MessageCreateRequest ¶
type MessageCreateRequest struct { ChannelID string `json:"channelid"` Content *MessageContent `json:"content"` Type MessageType `json:"type"` }
type MessageDirection ¶
type MessageDirection string
const ( // MessageDirectionReceived indicates an inbound message received from the customer. MessageDirectionReceived MessageDirection = "received" // MessageDirectionSent indicates an outbound message sent from the API. MessageDirectionSent MessageDirection = "sent" )
type MessageList ¶
func ListMessages ¶
func ListMessages(c *messagebird.Client, conversationID string, options *ListOptions) (*MessageList, error)
ListMessages gets a collection of messages from a conversation. Pagination can be set in the options.
type MessageStatus ¶
type MessageStatus string
MessageStatus is a field set by the API. It indicates what the state of the message is, e.g. whether it has been successfully delivered or read.
const ( MessageStatusDeleted MessageStatus = "deleted" MessageStatusDelivered MessageStatus = "delivered" MessageStatusFailed MessageStatus = "failed" MessageStatusPending MessageStatus = "pending" MessageStatusRead MessageStatus = "read" MessageStatusReceived MessageStatus = "received" MessageStatusSent MessageStatus = "sent" MessageStatusUnsupported MessageStatus = "unsupported" MessageStatusRejected MessageStatus = "rejected" )
type MessageType ¶
type MessageType string
MessageType indicates what kind of content a Message has, e.g. audio or text.
const ( MessageTypeAudio MessageType = "audio" MessageTypeFile MessageType = "file" MessageTypeHSM MessageType = "hsm" MessageTypeImage MessageType = "image" MessageTypeLocation MessageType = "location" MessageTypeText MessageType = "text" MessageTypeVideo MessageType = "video" )
type MessagesCount ¶
type StartRequest ¶
type StartRequest struct { ChannelID string `json:"channelId"` Content *MessageContent `json:"content"` To string `json:"to"` Type MessageType `json:"type"` }
StartRequest contains the request data for the Start endpoint.
type UpdateRequest ¶
type UpdateRequest struct {
Status ConversationStatus `json:"status"`
}
UpdateRequest contains the request data for the Update endpoint.
type Webhook ¶
type Webhook struct { ID string ChannelID string Events []WebhookEvent URL string Status WebhookStatus CreatedDatetime *time.Time UpdatedDatetime *time.Time }
func CreateWebhook ¶
func CreateWebhook(c *messagebird.Client, req *WebhookCreateRequest) (*Webhook, error)
CreateWebhook registers a webhook that is invoked when something interesting happens.
func ReadWebhook ¶
func ReadWebhook(c *messagebird.Client, id string) (*Webhook, error)
ReadWebhook gets a single webhook based on its ID.
func UpdateWebhook ¶
func UpdateWebhook(c *messagebird.Client, id string, req *WebhookUpdateRequest) (*Webhook, error)
UpdateWebhook updates a single webhook based on its ID with any values set in WebhookUpdateRequest. Do not set any values that should not be updated.
type WebhookCreateRequest ¶
type WebhookCreateRequest struct { ChannelID string `json:"channelId"` Events []WebhookEvent `json:"events"` URL string `json:"url"` }
type WebhookEvent ¶
type WebhookEvent string
const ( WebhookEventConversationCreated WebhookEvent = "conversation.created" WebhookEventConversationUpdated WebhookEvent = "conversation.updated" WebhookEventMessageCreated WebhookEvent = "message.created" WebhookEventMessageUpdated WebhookEvent = "message.updated" )
type WebhookList ¶
func ListWebhooks ¶
func ListWebhooks(c *messagebird.Client, options *ListOptions) (*WebhookList, error)
ListWebhooks gets a collection of webhooks. Pagination can be set in options.
type WebhookStatus ¶
type WebhookStatus string
WebhookStatus indicates what state a Webhook is in. At the moment there are only 2 statuses; enabled or disabled.
const ( // WebhookStatusEnabled indictates that the webhook is enabled. WebhookStatusEnabled WebhookStatus = "enabled" // WebhookStatusDisabled indictates that the webhook is disabled. WebhookStatusDisabled WebhookStatus = "disabled" )
type WebhookUpdateRequest ¶
type WebhookUpdateRequest struct { Events []WebhookEvent `json:"events,omitempty"` URL string `json:"url,omitempty"` Status WebhookStatus `json:"status,omitempty"` }