Skip to content

Commit

Permalink
Create function to normalize quick replies
Browse files Browse the repository at this point in the history
  • Loading branch information
Robi9 committed Sep 15, 2023
1 parent b80db3e commit 7eeffc9
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions handlers/weniwebchat/weniwebchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat

// add quickreplies on last message
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)
}
qrs := normalizeQuickReplies(msg.QuickReplies())
payload.Message.QuickReplies = qrs
}

Expand All @@ -216,19 +205,7 @@ 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.QuickReplies = qrs
qrs := normalizeQuickReplies(msg.QuickReplies())
payload.Message = moMessage{
Type: "text",
TimeStamp: getTimestamp(),
Expand Down Expand Up @@ -282,3 +259,19 @@ func getTimestamp() string {

return fmt.Sprint(time.Now().Unix())
}

func normalizeQuickReplies(quickReplies []string) []string {
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 qrs
}

0 comments on commit 7eeffc9

Please sign in to comment.