Skip to content

Commit

Permalink
Fix quick replies for wwc
Browse files Browse the repository at this point in the history
  • Loading branch information
Robi9 committed Sep 15, 2023
1 parent c80f862 commit c5a04b5
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions handlers/weniwebchat/weniwebchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,21 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}

// add quickreplies on last message
// if i == lenAttachments-1 {
// payload.Message.QuickReplies = msg.QuickReplies()
// }
if i == lenAttachments-1 {
var text string
var qrs []string
for _, qr := range msg.QuickReplies() {
if strings.Contains(qr, "\\/") {
text = strings.Replace(qr, "\\", "", -1)
} else if strings.Contains(qr, "\\\\") {
text = strings.Replace(qr, "\\\\", "\\", -1)
} else {
text = qr
}
qrs = append(qrs, text)
}
payload.Message.QuickReplies = qrs
}

// build request
var body []byte
Expand All @@ -204,10 +216,23 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}
}
} else {
var text string
var qrs []string
for _, qr := range msg.QuickReplies() {
if strings.Contains(qr, "\\/") {
text = strings.Replace(qr, "\\", "", -1)
} else if strings.Contains(qr, "\\\\") {
text = strings.Replace(qr, "\\\\", "\\", -1)
} else {
text = qr
}
qrs = append(qrs, text)
}
payload.Message = moMessage{
Type: "text",
TimeStamp: getTimestamp(),
Text: msg.Text(),
Type: "text",
TimeStamp: getTimestamp(),
Text: msg.Text(),
QuickReplies: qrs,
}
// build request
body, err := json.Marshal(&payload)
Expand Down Expand Up @@ -239,25 +264,12 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}

func newOutgoingMessage(payType, to, from string, quickReplies []string) *moPayload {
var text string
var qrs []string
for _, qr := range quickReplies {
if strings.Contains(qr, "\\/") {
text = strings.Replace(qr, "\\", "", -1)
} else if strings.Contains(qr, "\\\\") {
text = strings.Replace(qr, "\\\\", "\\", -1)
} else {
text = qr
}
qrs = append(qrs, text)
}

return &moPayload{
Type: payType,
To: to,
From: from,
Message: moMessage{
QuickReplies: qrs,
QuickReplies: quickReplies,
},
}
}
Expand Down

0 comments on commit c5a04b5

Please sign in to comment.