1
0
mirror of synced 2024-11-21 20:46:05 +03:00

package godoc

This commit is contained in:
Pavel 2023-12-29 11:30:09 +03:00
parent 90a50feccb
commit a02b1fe885
2 changed files with 18 additions and 50 deletions

View File

@ -10,7 +10,6 @@
// deadline := time.Now().Add(after)
// return &deadline
// }
//
// resp, status, err := client.Messages(SendData{
// Message: Message{
// ExternalID: "uid_1",
@ -37,57 +36,20 @@
// },
// Channel: 305,
// ExternalChatID: "chat_id_1",
// ReplyDeadline: getReplyDeadline(24 * time.Hour),
// ReplyDeadline: getReplyDeadline(24 * time.Hour),
// })
// if err != nil {
// log.Fatalf("request error: %s (%d)", err, status)
// 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)
// }
//
// log.Printf("status: %d, message ID: %d", status, resp.MessageID)
package v1
import (
"log"
"time"
)
func ooga() {
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",
ReplyDeadline: getReplyDeadline(24 * time.Hour),
})
if err != nil {
log.Fatalf("request error: %s (%d)", err, status)
}
log.Printf("status: %d, message ID: %d", status, resp.MessageID)
}

View File

@ -85,6 +85,12 @@ func NewServerError(response *http.Response) error {
func AsClientError(err error) *HTTPClientError {
for {
if err == nil {
return nil
}
if typed, ok := err.(*HTTPClientError); ok {
return typed
}
err = errors.Unwrap(err)
}
}