-
Notifications
You must be signed in to change notification settings - Fork 1
/
conversation_event.go
67 lines (52 loc) · 2.19 KB
/
conversation_event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package client
import (
"context"
"fmt"
"net/http"
"time"
)
// ConversationEventType describes an event that occurred within the conversation.
type ConversationEventType string
const (
// ConversationEventTypeTyping means the customer or human agent started typing.
ConversationEventTypeTyping ConversationEventType = "typing"
// ConversationEventTypeMessageDelivered means that a message has been delivered
// to a participant
ConversationEventTypeMessageDelivered ConversationEventType = "delivered"
// ConversationEventTypeMessageDelivered means that a message has been read
// by the participant it was delivered to
ConversationEventTypeMessageRead ConversationEventType = "read"
// ConversationEventTypeJoin means the customer or human agent joined the
// conversation.
ConversationEventTypeJoin ConversationEventType = "join"
// ConversationEventTypeLeave means the customer or human agent left the
// conversation.
ConversationEventTypeLeave ConversationEventType = "leave"
)
type EventParams struct {
// Type identifies the type of event (see: ConversationEventType).
Type ConversationEventType `json:"type"`
// ParticipantID identifies the message sender.
ParticipantID string `json:"participant_id"`
// ParticipantType identifies the type of participant who sent this message.
ParticipantType ParticipantType `json:"participant_type"`
// MessageID optionally identifies the message that this event relates to
MessageID *string `json:"message_id,omitempty"`
// Timestamp optionally defines the time when the conversation was assigned.
// If not given, this will default to the current time.
Timestamp *time.Time `json:"timestamp,omitempty"`
// IdempotencyKey optionally enables you to safely retry requests
IdempotencyKey string `json:"idempotency_key,omitempty"`
}
// AddConversationEvent records an event such as the customer started typing.
func (c *Client) AddConversationEvent(ctx context.Context, conversationID string, p *EventParams) error {
rsp, err := c.makeRequest(ctx, http.MethodPost, fmt.Sprintf("conversations/%s/events", conversationID), p)
if err != nil {
return err
}
defer rsp.Body.Close()
if err := responseError(rsp); err != nil {
return err
}
return nil
}