Skip to content

Commit

Permalink
Merge pull request nyaruka#442 from nyaruka/fix-telegram-stop
Browse files Browse the repository at this point in the history
Add log to status first when blocked
  • Loading branch information
rowanseymour authored May 9, 2022
2 parents 52bec90 + bea7f18 commit adaa1db
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions handlers/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}

externalID, log, botBlocked, err := h.sendMsgPart(msg, authToken, "sendMessage", form, msgKeyBoard)
status.AddLog(log)
if botBlocked {
status.SetStatus(courier.MsgFailed)
channelEvent := h.Backend().NewChannelEvent(msg.Channel(), courier.StopContact, msg.URN())
Expand All @@ -227,7 +228,6 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}
status.SetExternalID(externalID)
hasError = err != nil
status.AddLog(log)

}

Expand All @@ -247,6 +247,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
"caption": []string{caption},
}
externalID, log, botBlocked, err := h.sendMsgPart(msg, authToken, "sendPhoto", form, attachmentKeyBoard)
status.AddLog(log)
if botBlocked {
status.SetStatus(courier.MsgFailed)
channelEvent := h.Backend().NewChannelEvent(msg.Channel(), courier.StopContact, msg.URN())
Expand All @@ -255,7 +256,6 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}
status.SetExternalID(externalID)
hasError = err != nil
status.AddLog(log)

case "video":
form := url.Values{
Expand All @@ -264,6 +264,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
"caption": []string{caption},
}
externalID, log, botBlocked, err := h.sendMsgPart(msg, authToken, "sendVideo", form, attachmentKeyBoard)
status.AddLog(log)
if botBlocked {
status.SetStatus(courier.MsgFailed)
channelEvent := h.Backend().NewChannelEvent(msg.Channel(), courier.StopContact, msg.URN())
Expand All @@ -272,7 +273,6 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}
status.SetExternalID(externalID)
hasError = err != nil
status.AddLog(log)

case "audio":
form := url.Values{
Expand All @@ -281,6 +281,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
"caption": []string{caption},
}
externalID, log, botBlocked, err := h.sendMsgPart(msg, authToken, "sendAudio", form, attachmentKeyBoard)
status.AddLog(log)
if botBlocked {
status.SetStatus(courier.MsgFailed)
channelEvent := h.Backend().NewChannelEvent(msg.Channel(), courier.StopContact, msg.URN())
Expand All @@ -289,7 +290,6 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}
status.SetExternalID(externalID)
hasError = err != nil
status.AddLog(log)

case "application":
form := url.Values{
Expand All @@ -298,6 +298,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
"caption": []string{caption},
}
externalID, log, botBlocked, err := h.sendMsgPart(msg, authToken, "sendDocument", form, attachmentKeyBoard)
status.AddLog(log)
if botBlocked {
status.SetStatus(courier.MsgFailed)
channelEvent := h.Backend().NewChannelEvent(msg.Channel(), courier.StopContact, msg.URN())
Expand All @@ -306,7 +307,6 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}
status.SetExternalID(externalID)
hasError = err != nil
status.AddLog(log)

default:
status.AddLog(courier.NewChannelLog("Unknown media type: "+mediaType, msg.Channel(), msg.ID(), "", "", courier.NilStatusCode,
Expand Down

0 comments on commit adaa1db

Please sign in to comment.