feat(semaphore,telegram): a template's summary fills in this action's values, and a tapped request loses its buttons (archie #1984, #2001)
publish / publish (push) Successful in 1m14s

This commit is contained in:
sam committed 2026-11-16 04:51:23 +11:00
1 parent 79047f9617
commit 89ea431ea1
2 files changed
+33 -4

No files matched your search

+13 -1
View File
@@ -216,12 +216,24 @@ func (s *semaphore) Resolve(_ context.Context, action string, raw jsontext.Value
if err != nil {
return nil, err
}
effect := s.effect(t)
effect.Summary = fill(effect.Summary, in)
return &connectorv1.ResolveResponse{
Target: &connectorv1.Target{Kind: t.Target.Kind, Id: in.Host, Environment: t.Target.Environment, Disposable: t.Target.Disposable},
Effect: s.effect(t),
Effect: effect,
}, nil
}
// fill puts this action's values into a declared summary's {host} and {var}
// placeholders, so the person approving it reads what this one does.
func fill(summary string, in actionInput) string {
pairs := []string{"{host}", in.Host}
for name, v := range in.Vars {
pairs = append(pairs, "{"+name+"}", v)
}
return strings.NewReplacer(pairs...).Replace(summary)
}
type task struct {
ID int `json:"id"`
TemplateID int `json:"template_id"`
+20 -3
View File
@@ -127,8 +127,14 @@ func (t *telegram) Deliver(ctx context.Context, delivery string, input jsontext.
type update struct {
UpdateID int64 `json:"update_id"`
Callback *struct {
ID string `json:"id"`
Data string `json:"data"`
ID string `json:"id"`
Data string `json:"data"`
Message *struct {
MessageID int64 `json:"message_id"`
Chat struct {
ID int64 `json:"id"`
} `json:"chat"`
} `json:"message"`
From struct {
ID int64 `json:"id"`
FirstName string `json:"first_name"`
@@ -205,9 +211,20 @@ func (t *telegram) answer(ctx context.Context, u update) (*connector.Event, func
if err != nil {
return nil, tell("That answer couldn't be read.")
}
received := tell("Answer received.")
return &connector.Event{
Type: answerType, SourceEventID: "update:" + strconv.FormatInt(u.UpdateID, 10), Fields: fields, OccurredAt: time.Now().UTC(),
}, tell("Answer received.")
}, func() {
received()
// The buttons go once the answer is stored, so nobody taps a settled
// request again.
if q.Message != nil {
_ = t.call(ctx, "editMessageReplyMarkup", map[string]any{
"chat_id": q.Message.Chat.ID, "message_id": q.Message.MessageID,
"reply_markup": map[string]any{"inline_keyboard": [][]any{}},
}, nil)
}
}
}
// parseAnswer reads a button's data: "answer:<yes|no>:<request id>".