Skip to content

Commit

Permalink
Merge pull request #83 from istresearch/dev/PE-370 into main
Browse files Browse the repository at this point in the history
PE-370 - Use scheme for processing
  • Loading branch information
baracudda authored Jun 24, 2024
2 parents c25adff + 61f88c3 commit 9b3a7a7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
echo "::notice::Version STR=${VERSION_STR}${ALT_TAGS}"
- name: "Create Release"
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
66 changes: 24 additions & 42 deletions handlers/postmaster/postmaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
}

var urn urns.URN
mode := strings.ToUpper(payload.Mode)

if len(channel.Schemes()) < 1 {
return nil, fmt.Errorf("no scheme set for channel %s", channel.UUID())
Expand All @@ -128,7 +127,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
urns.ValidSchemes[scheme] = true

//Handle SMS (tel) specially, everything else is a straight string passthrough
if mode == "SMS" {
if scheme == "tel" {
// Remove out + and - just in case
value := payload.Contact.Value
value = strings.Replace(value, " ", "", -1)
Expand Down Expand Up @@ -200,11 +199,6 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
return nil, err
}

chatMode := msg.Channel().ConfigForKey("chat_mode", "").(string)
if chatMode == "" {
return nil, fmt.Errorf("invalid chat mode")
}

deviceId := msg.Channel().Address()

status := h.Backend().NewMsgStatusForID(msg.Channel(), msg.ID(), courier.MsgErrored)
Expand All @@ -227,9 +221,9 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
payload.Contact.Name = string(dbContact.Name_)
payload.Contact.Value = msg.URN().Path()
payload.Text = part
payload.Mode = strings.ToUpper(chatMode)
payload.ChannelID = msg.Channel().UUID().String()
payload.DeviceID = deviceId
payload.Scheme = msg.Channel().Schemes()[0]
payload.ID = fmt.Sprintf("%d", msg.ID())

for _, attachment := range msg.Attachments() {
Expand Down Expand Up @@ -274,16 +268,8 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}

func (h *handler) PurgeOutgoing(ctx context.Context, channel courier.Channel) error {
chatMode := channel.ConfigForKey("chat_mode", "").(string)
if chatMode == "" {
return fmt.Errorf("invalid chat mode")
}

deviceID := channel.Address()

pr := purgeRequest{
DeviceID: deviceID,
Mode: chatMode,
ChannelId: channel.UUID().String(),
}

apiUrl, err := getPostofficeEndpoint()
Expand Down Expand Up @@ -356,7 +342,6 @@ Content-Type: application/json; charset=utf-8
"name": "Bob",
"value": "tel:+11234567890"
},
"mode": "sms",
"channel_id": "7cc23772-e933-47b4-b025-19cbaec01edf",
"media": ["http://example.com/example.jpg"]
}
Expand All @@ -369,59 +354,56 @@ type incomingMessage struct {
Name string `json:"name"`
Value string `json:"value" validate:"required"`
} `json:"contact" validate:"required"`
Mode string `json:"mode" validate:"required"`
ChannelID string `json:"channel_id" validate:"required"`

Media []string ` json:"media"`
}

/*
{
"text": "bla",
"contact": {
"name": "Bob",
"value": "tel:+11234567890"
},
"mode": "sms",
"channel_id": "7cc23772-e933-47b4-b025-19cbaec01edf",
"device_id": "7cc23773-e933-47b4-b025-19cbaec01edf",
"id": "32423432432",
"media": ["http://example.com/example.jpg"]
}
{
"text": "bla",
"contact": {
"name": "Bob",
"value": "tel:+11234567890"
},
"channel_id": "7cc23772-e933-47b4-b025-19cbaec01edf",
"device_id": "7cc23773-e933-47b4-b025-19cbaec01edf",
"id": "32423432432",
"media": ["http://example.com/example.jpg"]
}
*/
type outgoingMessage struct {
Text string `json:"text" validate:"required"`
Contact struct {
Name string `json:"name"`
Value string `json:"value" validate:"required"`
} `json:"contact" validate:"required"`
Mode string `json:"mode" validate:"required"`
DeviceID string `json:"device_id" validate:"required"`
ChannelID string `json:"channel_id" validate:"required"`
Scheme string `json:"scheme" validate:"required"`

ID string `json:"id" validate:"required"`

Media []string ` json:"media"`
}

/*
{
"message_id": "1234",
"status": "S"
}
{
"message_id": "1234",
"status": "S"
}
*/
type messageStatus struct {
MessageID string `json:"message_id" validate:"required"`
Status string `json:"status" validate:"required"`
}

/*
{
"device_id": "123",
"mode": "SMS"
}
{
"device_id": "123",
"channel_id": "12121-dsfsdf-3243-dsfsdf-2323"
}
*/
type purgeRequest struct {
DeviceID string `json:"device_id" validate:"required"`
Mode string `json:"mode" validate:"required"`
ChannelId string `json:"channel_id"`
}

0 comments on commit 9b3a7a7

Please sign in to comment.