Skip to content

Commit

Permalink
Merge branch 'release/0.7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas committed Nov 25, 2021
2 parents f153d10 + e862f4c commit 878e3cd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 31 deletions.
2 changes: 1 addition & 1 deletion examples/OpenMessaging/chat-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (server *ChatServer) Start(config *Config) {
if err != nil {
Log.Errorf("Failed to send inbound", err)
} else {
Log.Record("message", inboundResult.OpenMessage).Record("result", inboundResult).Infof("Message sent successfully")
Log.Record("message", inboundResult).Record("result", inboundResult).Infof("Message sent successfully")
}

log.Infof("Message sent to GENESYS Cloud")
Expand Down
29 changes: 18 additions & 11 deletions openmessaging_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type OpenMessagingIntegration struct {
ModifiedBy *DomainEntityRef `json:"modifiedBy,omitempty"`
CreateStatus string `json:"createStatus,omitempty"` // Initiated, Completed, Error
CreateError *ErrorBody `json:"createError,omitempty"`
Status string `json:"status,omitempty"` // Active, Inactive
SelfURI URI `json:"selfUri,omitempty"`
client *Client `json:"-"`
logger *logger.Logger `json:"-"`
Expand Down Expand Up @@ -222,12 +223,15 @@ func (integration *OpenMessagingIntegration) Update(context context.Context, nam
// SendInboundTextMessage sends a text message from the middleware to GENESYS Cloud
//
// See https://developer.genesys.cloud/api/digital/openmessaging/inboundMessages#send-an-inbound-open-message
func (integration *OpenMessagingIntegration) SendInboundMessage(context context.Context, from *OpenMessageFrom, messageID, text string) (*OpenMessageResult, error) {
func (integration *OpenMessagingIntegration) SendInboundMessage(context context.Context, from *OpenMessageFrom, messageID, text string) (id string, err error) {
if integration.ID == uuid.Nil {
return nil, errors.ArgumentMissing.With("ID")
return "", errors.ArgumentMissing.With("ID")
}
result := &OpenMessageResult{}
err := integration.client.Post(
if len(messageID) == 0 {
return "", errors.ArgumentMissing.With("messageID")
}
result := OpenMessageText{}
err = integration.client.Post(
integration.logger.ToContext(context),
"/conversations/messages/inbound/open",
&OpenMessageText{
Expand All @@ -241,19 +245,22 @@ func (integration *OpenMessagingIntegration) SendInboundMessage(context context.
},
&result,
)
return result, err
return result.ID, err
}

// SendInboundAudioMessage sends a text message from the middleware to GENESYS Cloud
//
// See https://developer.genesys.cloud/api/digital/openmessaging/inboundMessages#inbound-message-with-attached-photo
// See https://developer.genesys.cloud/api/rest/v2/conversations/#post-api-v2-conversations-messages-inbound-open
func (integration *OpenMessagingIntegration) SendInboundMessageWithAttachment(context context.Context, from *OpenMessageFrom, messageID, text string, attachmentURL *url.URL, attachmentMimeType, attachmentID string) (*OpenMessageResult, error) {
func (integration *OpenMessagingIntegration) SendInboundMessageWithAttachment(context context.Context, from *OpenMessageFrom, messageID, text string, attachmentURL *url.URL, attachmentMimeType, attachmentID string) (id string, err error) {
if integration.ID == uuid.Nil {
return nil, errors.ArgumentMissing.With("ID")
return "", errors.ArgumentMissing.With("ID")
}
if len(messageID) == 0 {
return "", errors.ArgumentMissing.With("messageID")
}
if attachmentURL == nil {
return nil, errors.ArgumentMissing.With("url")
return "", errors.ArgumentMissing.With("url")
}

var attachmentType string
Expand All @@ -280,8 +287,8 @@ func (integration *OpenMessagingIntegration) SendInboundMessageWithAttachment(co
attachmentFilename = strings.ToLower(attachmentType) + "-" + fileID + fileExtension
}

result := &OpenMessageResult{}
err := integration.client.Post(
result := OpenMessageText{}
err = integration.client.Post(
integration.logger.ToContext(context),
"/conversations/messages/inbound/open",
&OpenMessageText{
Expand All @@ -307,7 +314,7 @@ func (integration *OpenMessagingIntegration) SendInboundMessageWithAttachment(co
},
&result,
)
return result, err
return result.ID, err
}

// SendOutboundMessage sends a message from GENESYS Cloud to the middleware
Expand Down
5 changes: 1 addition & 4 deletions openmessaging_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import (
)

type OpenMessage interface {
GetID() string
core.TypeCarrier
}

type OpenMessageResult struct {
OpenMessage
}

var openMessageRegistry = core.TypeRegistry{}

func UnmarshalOpenMessage(payload []byte) (OpenMessage, error) {
Expand Down
19 changes: 13 additions & 6 deletions openmessaging_message_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
//
// See: https://developer.genesys.cloud/api/digital/openmessaging/receipts
type OpenMessageReceipt struct {
ID string `json:"id,omitempty"` // Can be anything
Channel *OpenMessageChannel `json:"channel"`
Direction string `json:"direction"`
Status string `json:"status"`
Reasons []*StatusReason `json:"reasons,omitempty"`
FinalReceipt bool `json:"isFinalReceipt"`
ID string `json:"id,omitempty"` // Can be anything, message ID this receipt relates to
Channel *OpenMessageChannel `json:"channel"`
Direction string `json:"direction"` // Can be "Inbound" or "Outbound"
Status string `json:"status"` // Can be "Published" (Inbound), "Delivered" (Outbound), "Failed"
Reasons []*StatusReason `json:"reasons,omitempty"` // Contains the reason for the failure
FinalReceipt bool `json:"isFinalReceipt"` // True if this is the last receipt about this message ID
Metadata map[string]string `json:"metadata,omitempty"`
}

type StatusReason struct {
Expand All @@ -35,6 +36,12 @@ func (message OpenMessageReceipt) GetType() string {
return "Receipt"
}

// GetID gets the identifier of this
// implements OpenMessage
func (message OpenMessageReceipt) GetID() string {
return message.ID
}

// IsFailed tells if the receipt is failed
func (message OpenMessageReceipt) IsFailed() bool {
return message.Status == "Failed"
Expand Down
25 changes: 17 additions & 8 deletions openmessaging_message_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import (
"github.com/gildas/go-errors"
)

// OpenMessageText is a text message sent or received by the Open Messaging API
//
// See: https://developer.genesys.cloud/api/rest/v2/conversations/#post-api-v2-conversations-messages-inbound-open
type OpenMessageText struct {
ID string `json:"id,omitempty"` // Can be anything
Channel *OpenMessageChannel `json:"channel"`
Direction string `json:"direction"`
Text string `json:"text"`
Content []*OpenMessageContent `json:"content,omitempty"`
RelatedMessages []*OpenMessageText `json:"relatedMessages,omitempty"`
ID string `json:"id,omitempty"` // Can be anything
Channel *OpenMessageChannel `json:"channel"`
Direction string `json:"direction"`
Text string `json:"text"`
Content []*OpenMessageContent `json:"content,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}

// init initializes this type
func init() {
openMessageRegistry.Add(OpenMessageReceipt{})
openMessageRegistry.Add(OpenMessageText{})
}

// GetType tells the type of this OpenMessage
Expand All @@ -27,6 +30,12 @@ func (message OpenMessageText) GetType() string {
return "Text"
}

// GetID gets the identifier of this
// implements OpenMessage
func (message OpenMessageText) GetID() string {
return message.ID
}

// Redact redacts sensitive data
//
// implements logger.Redactable
Expand Down Expand Up @@ -62,7 +71,7 @@ func (message *OpenMessageText) UnmarshalJSON(data []byte) (err error) {
if err = json.Unmarshal(data, &inner); err != nil {
return errors.JSONUnmarshalError.Wrap(err)
}
if inner.Type != (OpenMessageReceipt{}).GetType() {
if inner.Type != (OpenMessageText{}).GetType() {
return errors.JSONUnmarshalError.Wrap(errors.InvalidType.With(inner.Type))
}
*message = OpenMessageText(inner.surrogate)
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package gcloudcx
var commit string

// VERSION is the version of this application
var VERSION = "0.7.0" + commit
var VERSION = "0.7.1" + commit

// APP is the name of the application
const APP string = "GCloudCX Client"

0 comments on commit 878e3cd

Please sign in to comment.