2023-12-29 11:24:23 +03:00
|
|
|
// Package v1 provides Go API Client implementation for MessageGateway Transport API.
|
|
|
|
//
|
2023-12-29 11:44:18 +03:00
|
|
|
// You can use v1.New or v1.NewWithClient to initialize API client.
|
|
|
|
// The package github.com/retailcrm/mg-transport-api-client-go/examples contains some examples on how to
|
|
|
|
// use this library properly.
|
2023-12-29 11:24:23 +03:00
|
|
|
//
|
|
|
|
// Basic usage example:
|
|
|
|
//
|
|
|
|
// client := New("https://message-gateway.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")
|
|
|
|
// getReplyDeadline := func(after time.Duration) *time.Time {
|
|
|
|
// deadline := time.Now().Add(after)
|
|
|
|
// return &deadline
|
|
|
|
// }
|
|
|
|
// resp, status, err := client.Messages(SendData{
|
|
|
|
// Message: Message{
|
|
|
|
// ExternalID: "uid_1",
|
|
|
|
// Type: MsgTypeText,
|
|
|
|
// Text: "Hello customer!",
|
|
|
|
// PageLink: "https://example.com",
|
|
|
|
// },
|
|
|
|
// Originator: OriginatorCustomer,
|
|
|
|
// Customer: Customer{
|
|
|
|
// ExternalID: "client_id_1",
|
|
|
|
// Nickname: "customer",
|
|
|
|
// Firstname: "Tester",
|
|
|
|
// Lastname: "Tester",
|
|
|
|
// Avatar: "https://example.com/image.png",
|
|
|
|
// ProfileURL: "https://example.com/user/client_id_1",
|
|
|
|
// Language: "en",
|
|
|
|
// Utm: &Utm{
|
|
|
|
// Source: "myspace.com",
|
|
|
|
// Medium: "social",
|
|
|
|
// Campaign: "something",
|
|
|
|
// Term: "fedora",
|
|
|
|
// Content: "autumn_collection",
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// Channel: 305,
|
|
|
|
// ExternalChatID: "chat_id_1",
|
2023-12-29 11:30:09 +03:00
|
|
|
// ReplyDeadline: getReplyDeadline(24 * time.Hour),
|
2023-12-29 11:24:23 +03:00
|
|
|
// })
|
|
|
|
// if err != nil {
|
2023-12-29 11:30:09 +03:00
|
|
|
// if clientErr := AsClientError(err); clientErr != nil {
|
|
|
|
// if clientErr.BaseError != nil {
|
|
|
|
// log.Fatalf("cannot perform the request: %s", clientErr.BaseError)
|
|
|
|
// }
|
|
|
|
// if clientErr.ErrorMsg != "" {
|
|
|
|
// log.Fatalf("MG error: %s", clientErr.ErrorMsg)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// log.Fatalf("general error: %s (%d)", err, status)
|
2023-12-29 11:24:23 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// log.Printf("status: %d, message ID: %d", status, resp.MessageID)
|
|
|
|
package v1
|