diff --git a/connectors/telegram/main.go b/connectors/telegram/main.go new file mode 100644 index 0000000..de814e0 --- /dev/null +++ b/connectors/telegram/main.go @@ -0,0 +1,13 @@ +// Command telegram is the Telegram connector: it delivers messages, with +// Approve and Deny buttons on an approval request, to the private chats of +// the users an operator allows, and listens for their taps. A tap becomes an +// approval.answer event, so an answer reaches Archie the way every event does. +package main + +import "github.com/samcharles93/archipelago/sdk/connector" + +func main() { + connector.Serve(func(cfg connector.Config) (connector.Connector, error) { + return newTelegram(cfg) + }) +} diff --git a/connectors/telegram/package.yaml b/connectors/telegram/package.yaml new file mode 100644 index 0000000..3e83b6f --- /dev/null +++ b/connectors/telegram/package.yaml @@ -0,0 +1,11 @@ +apiVersion: dev.archie.package.v1 +displayName: Telegram +description: Delivers messages and approval requests to the Telegram users an operator allows, and turns their Approve and Deny taps into approval.answer events. The user_ids setting lists who may answer; the bot credential slot holds the bot token. +version: 0.1.0 +contributes: + extensions: + - surface: connector + path: bin/telegram +files: + - path: bin/telegram + mode: 493 diff --git a/connectors/telegram/telegram.go b/connectors/telegram/telegram.go new file mode 100644 index 0000000..0dd77bc --- /dev/null +++ b/connectors/telegram/telegram.go @@ -0,0 +1,272 @@ +package main + +import ( + "bytes" + "context" + "encoding/json/jsontext" + json "encoding/json/v2" + "errors" + "fmt" + "io" + "net/http" + "net/url" + "slices" + "strconv" + "strings" + "time" + + "github.com/samcharles93/archipelago/sdk/connector" + connectorv1 "github.com/samcharles93/archipelago/sdk/connector/v1" +) + +const ( + botAPI = "https://api.telegram.org" + pollSeconds = 25 + answerPrefix = "answer:" + answerType = "approval.answer" +) + +type telegram struct { + token string + users []int64 + api string + client *http.Client +} + +func newTelegram(cfg connector.Config) (*telegram, error) { + token := cfg.Secrets["bot.token"] + if token == "" { + return nil, errors.New("the bot credential slot needs a token") + } + var users []int64 + for f := range strings.SplitSeq(cfg.Settings["user_ids"], ",") { + if f = strings.TrimSpace(f); f == "" { + continue + } + id, err := strconv.ParseInt(f, 10, 64) + if err != nil || id <= 0 { + return nil, fmt.Errorf("user_ids: %q isn't a Telegram user id", f) + } + users = append(users, id) + } + if len(users) == 0 { + return nil, errors.New("user_ids needs at least one Telegram user id") + } + return &telegram{ + token: token, users: users, api: botAPI, + client: &http.Client{Timeout: (pollSeconds + 15) * time.Second}, + }, nil +} + +var ( + messageSchema = []byte(`{"type":"object","additionalProperties":false,"required":["title"],"properties":{` + + `"title":{"type":"string"},"body":{"type":"string"},` + + `"approval_request_id":{"type":"string","description":"Present on an approval request: adds Approve and Deny buttons."}}}`) + answerSchema = []byte(`{"type":"object","required":["request_id","approved","by"],"properties":{` + + `"request_id":{"type":"string"},"approved":{"type":"boolean"},` + + `"by":{"type":"string","description":"telegram:"},"by_name":{"type":"string"}}}`) +) + +func (t *telegram) Describe() connector.Description { + return connector.Description{ + Deliveries: []*connectorv1.DeliveryType{{ + Name: "message", Description: "A message to every allowed user's private chat.", InputSchema: messageSchema, + }}, + Events: []*connectorv1.EventType{{ + Name: answerType, Description: "An allowed user tapped Approve or Deny.", Schema: answerSchema, + }}, + } +} + +type message struct { + Title string `json:"title"` + Body string `json:"body"` + ApprovalRequestID string `json:"approval_request_id"` +} + +// Deliver writes the message to each allowed user. Telegram can't dedupe a +// send, so a delivery fails only when no chat got it: retrying a partial one +// would repeat it to the users who already have it. +func (t *telegram) Deliver(ctx context.Context, delivery string, input jsontext.Value, _ string) (string, error) { + if delivery != "message" { + return "", fmt.Errorf("no delivery named %q", delivery) + } + var m message + if err := json.Unmarshal(input, &m, json.RejectUnknownMembers(true)); err != nil { + return "", fmt.Errorf("message: %w", err) + } + text := m.Title + if m.Body != "" { + text += "\n\n" + m.Body + } + var ids []string + var failed []error + for _, chat := range t.users { + body := map[string]any{"chat_id": chat, "text": text, "link_preview_options": map[string]any{"is_disabled": true}} + if m.ApprovalRequestID != "" { + body["reply_markup"] = map[string]any{"inline_keyboard": [][]map[string]any{{ + {"text": "Approve", "callback_data": answerPrefix + "yes:" + m.ApprovalRequestID}, + {"text": "Deny", "callback_data": answerPrefix + "no:" + m.ApprovalRequestID}, + }}} + } + var sent struct { + MessageID int64 `json:"message_id"` + } + if err := t.call(ctx, "sendMessage", body, &sent); err != nil { + failed = append(failed, fmt.Errorf("chat %d: %w", chat, err)) + continue + } + ids = append(ids, strconv.FormatInt(chat, 10)+"/"+strconv.FormatInt(sent.MessageID, 10)) + } + if len(ids) == 0 { + return "", errors.Join(failed...) + } + return strings.Join(ids, ","), nil +} + +type update struct { + UpdateID int64 `json:"update_id"` + Callback *struct { + ID string `json:"id"` + Data string `json:"data"` + From struct { + ID int64 `json:"id"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Username string `json:"username"` + } `json:"from"` + } `json:"callback_query"` +} + +// Listen long-polls for taps. The cursor is Telegram's next update offset, so +// a batch the host didn't store is fetched again when it listens again. +func (t *telegram) Listen(ctx context.Context, cursor string, emit func([]connector.Event, string) error) error { + offset, _ := strconv.ParseInt(cursor, 10, 64) + for ctx.Err() == nil { + var updates []update + err := t.call(ctx, "getUpdates", map[string]any{ + "offset": offset, "timeout": pollSeconds, "allowed_updates": []string{"callback_query"}, + }, &updates) + if err != nil { + return err + } + if len(updates) == 0 { + continue + } + var events []connector.Event + var replies []func() + for _, u := range updates { + offset = max(offset, u.UpdateID+1) + e, reply := t.answer(ctx, u) + if e != nil { + events = append(events, *e) + } + if reply != nil { + replies = append(replies, reply) + } + } + if err := emit(events, strconv.FormatInt(offset, 10)); err != nil { + return err + } + // Only once the answers are stored does the person hear they were. + for _, r := range replies { + r() + } + } + return ctx.Err() +} + +// answer turns a tap into an event, and says what to tell the person. A tap +// from a user who isn't allowed is no event. +func (t *telegram) answer(ctx context.Context, u update) (*connector.Event, func()) { + q := u.Callback + if q == nil { + return nil, nil + } + tell := func(text string) func() { + return func() { + _ = t.call(ctx, "answerCallbackQuery", map[string]any{"callback_query_id": q.ID, "text": text}, nil) + } + } + if !slices.Contains(t.users, q.From.ID) { + return nil, tell("You're not allowed to answer this.") + } + approved, request, ok := parseAnswer(q.Data) + if !ok { + return nil, tell("That button is out of date.") + } + name := strings.TrimSpace(q.From.FirstName + " " + q.From.LastName) + if name == "" { + name = q.From.Username + } + fields, err := json.Marshal(map[string]any{ + "request_id": request, "approved": approved, "by": "telegram:" + strconv.FormatInt(q.From.ID, 10), "by_name": name, + }) + if err != nil { + return nil, tell("That answer couldn't be read.") + } + return &connector.Event{ + Type: answerType, SourceEventID: "update:" + strconv.FormatInt(u.UpdateID, 10), Fields: fields, OccurredAt: time.Now().UTC(), + }, tell("Answer received.") +} + +// parseAnswer reads a button's data: "answer::". +func parseAnswer(data string) (approved bool, request string, ok bool) { + rest, found := strings.CutPrefix(data, answerPrefix) + if !found { + return false, "", false + } + verdict, id, found := strings.Cut(rest, ":") + if !found || id == "" { + return false, "", false + } + switch verdict { + case "yes": + return true, id, true + case "no": + return false, id, true + } + return false, "", false +} + +// call posts one Bot API method and decodes its result into out. +func (t *telegram) call(ctx context.Context, method string, body, out any) error { + payload, err := json.Marshal(body) + if err != nil { + return err + } + req, err := http.NewRequestWithContext(ctx, http.MethodPost, t.api+"/bot"+t.token+"/"+method, bytes.NewReader(payload)) + if err != nil { + return err + } + req.Header.Set("Content-Type", "application/json") + res, err := t.client.Do(req) + if err != nil { + // The URL holds the token, so it never goes into an error. + var uerr *url.Error + if errors.As(err, &uerr) { + return fmt.Errorf("%s: %w", method, uerr.Err) + } + return fmt.Errorf("%s failed", method) + } + defer func() { _ = res.Body.Close() }() + raw, err := io.ReadAll(io.LimitReader(res.Body, 1<<20)) + if err != nil { + return fmt.Errorf("%s: %w", method, err) + } + var env struct { + OK bool `json:"ok"` + Description string `json:"description"` + Result jsontext.Value `json:"result"` + } + if err := json.Unmarshal(raw, &env); err != nil { + return fmt.Errorf("%s: %w", method, err) + } + if !env.OK { + return fmt.Errorf("%s: %s", method, env.Description) + } + if out == nil { + return nil + } + return json.Unmarshal(env.Result, out) +} diff --git a/connectors/telegram/telegram_test.go b/connectors/telegram/telegram_test.go new file mode 100644 index 0000000..d2f1ca5 --- /dev/null +++ b/connectors/telegram/telegram_test.go @@ -0,0 +1,126 @@ +package main + +import ( + "context" + json "encoding/json/v2" + "net/http" + "net/http/httptest" + "strings" + "sync" + "testing" + + "github.com/samcharles93/archipelago/sdk/connector" +) + +const fakeToken = "123:plainly-fake" //nolint:gosec // a fake bot token the test checks never leaks + +// fakeBot serves one batch of updates, then nothing, and records the replies +// to taps. +type fakeBot struct { + mu sync.Mutex + updates string + served bool + replies []string + // idle is called when the batch has been served and fetched past. + idle func() +} + +func (f *fakeBot) ServeHTTP(w http.ResponseWriter, r *http.Request) { + f.mu.Lock() + defer f.mu.Unlock() + switch { + case strings.HasSuffix(r.URL.Path, "/getUpdates"): + result := "[]" + if !f.served { + result, f.served = f.updates, true + } else if f.idle != nil { + f.idle() + } + _, _ = w.Write([]byte(`{"ok":true,"result":` + result + `}`)) + case strings.HasSuffix(r.URL.Path, "/answerCallbackQuery"): + var body struct { + Text string `json:"text"` + } + _ = json.UnmarshalRead(r.Body, &body) + f.replies = append(f.replies, body.Text) + _, _ = w.Write([]byte(`{"ok":true,"result":true}`)) + default: + w.WriteHeader(http.StatusNotFound) + } +} + +func tap(updateID, userID, data string) string { + return `{"update_id":` + updateID + `,"callback_query":{"id":"q` + updateID + `","data":"` + data + + `","from":{"id":` + userID + `,"first_name":"Sam"}}}` +} + +// TestOnlyAnAllowedUsersTapIsAnAnswer guards who may answer an approval: a tap +// becomes an approval.answer event only from a user the operator allowed and +// only for a well-formed button, and the cursor moves past every update so a +// refused tap isn't fetched again. +func TestOnlyAnAllowedUsersTapIsAnAnswer(t *testing.T) { + tests := []struct { + name string + update string + wantEvent string + wantReply string + }{ + {name: "an allowed user's approve is an answer", update: tap("7", "42", "answer:yes:req-1"), wantEvent: `"approved":true`, wantReply: "Answer received."}, + {name: "an allowed user's deny is an answer", update: tap("7", "42", "answer:no:req-1"), wantEvent: `"approved":false`, wantReply: "Answer received."}, + {name: "a user who isn't allowed is refused", update: tap("7", "99", "answer:yes:req-1"), wantReply: "You're not allowed to answer this."}, + {name: "a malformed button is refused", update: tap("7", "42", "answer:maybe:req-1"), wantReply: "That button is out of date."}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + bot := &fakeBot{updates: "[" + tt.update + "]"} + srv := httptest.NewServer(bot) + defer srv.Close() + tg, err := newTelegram(connector.Config{ + Settings: map[string]string{"user_ids": "42"}, Secrets: map[string]string{"bot.token": fakeToken}, + }) + if err != nil { + t.Fatal(err) + } + tg.api = srv.URL + ctx, cancel := context.WithCancel(t.Context()) + bot.idle = cancel + var got []connector.Event + var cursor string + _ = tg.Listen(ctx, "", func(events []connector.Event, c string) error { + got, cursor = events, c + return nil + }) + if cursor != "8" { + t.Fatalf("cursor = %q, want 8", cursor) + } + if tt.wantEvent == "" && len(got) != 0 { + t.Fatalf("got events %v, want none", got) + } + if tt.wantEvent != "" && (len(got) != 1 || got[0].Type != answerType || !strings.Contains(string(got[0].Fields), tt.wantEvent) || + !strings.Contains(string(got[0].Fields), `"by":"telegram:42"`)) { + t.Fatalf("got events %v, want one answer with %s by telegram:42", got, tt.wantEvent) + } + if len(bot.replies) != 1 || bot.replies[0] != tt.wantReply { + t.Fatalf("replies = %q, want %q", bot.replies, tt.wantReply) + } + }) + } +} + +// TestAFailedCallNeverShowsTheToken guards the bot token: it travels in the +// request URL, and a transport error must not carry that URL into a log. +func TestAFailedCallNeverShowsTheToken(t *testing.T) { + srv := httptest.NewServer(http.NotFoundHandler()) + srv.Close() + tg, err := newTelegram(connector.Config{ + Settings: map[string]string{"user_ids": "42"}, Secrets: map[string]string{"bot.token": fakeToken}, + }) + if err != nil { + t.Fatal(err) + } + tg.api = srv.URL + _, err = tg.Deliver(t.Context(), "message", []byte(`{"title":"hi"}`), "k") + if err == nil || strings.Contains(err.Error(), fakeToken) { + t.Fatalf("err = %v, want an error without the token", err) + } +} diff --git a/sdk/connector/connector.go b/sdk/connector/connector.go index 29d09ab..3d497ea 100644 --- a/sdk/connector/connector.go +++ b/sdk/connector/connector.go @@ -24,9 +24,10 @@ type Config struct { // Description declares what a connector hears, does and answers. type Description struct { - Events []*connectorv1.EventType - Actions []*connectorv1.ActionType - Lookups []*connectorv1.LookupType + Events []*connectorv1.EventType + Actions []*connectorv1.ActionType + Lookups []*connectorv1.LookupType + Deliveries []*connectorv1.DeliveryType } // Event is one typed event parsed from a verified payload. @@ -61,6 +62,20 @@ type Looker interface { Lookup(ctx context.Context, name string, input jsontext.Value) (output jsontext.Value, found bool, err error) } +// Deliverer sends deliveries: messages and records for people or a system of +// record. The host retries a failed delivery with the same idempotency key. +type Deliverer interface { + Deliver(ctx context.Context, delivery string, input jsontext.Value, idempotencyKey string) (externalID string, err error) +} + +// Listener holds its own connection to a source and emits its events from +// cursor on. emit stores a batch and the cursor to resume after it; Listen +// returns when ctx ends or the connection can't continue, and the host calls +// it again with the last stored cursor. +type Listener interface { + Listen(ctx context.Context, cursor string, emit func(events []Event, cursor string) error) error +} + // Digest identifies one concrete action, the same way archie-core does: its // name and its exact input. func Digest(action string, input []byte) string { diff --git a/sdk/connector/server.go b/sdk/connector/server.go index d9c6397..4beb841 100644 --- a/sdk/connector/server.go +++ b/sdk/connector/server.go @@ -42,7 +42,11 @@ func (s *server) Describe(context.Context, *connectorv1.DescribeRequest) (*conne return nil, err } d := c.Describe() - return &connectorv1.DescribeResponse{Contract: Contract, Events: d.Events, Actions: d.Actions, Lookups: d.Lookups}, nil + _, listens := c.(Listener) + return &connectorv1.DescribeResponse{ + Contract: Contract, Events: d.Events, Actions: d.Actions, Lookups: d.Lookups, + Deliveries: d.Deliveries, Listens: listens, + }, nil } func (s *server) Parse(ctx context.Context, req *connectorv1.ParseRequest) (*connectorv1.ParseResponse, error) { @@ -58,6 +62,10 @@ func (s *server) Parse(ctx context.Context, req *connectorv1.ParseRequest) (*con if err != nil { return nil, status.Errorf(codes.InvalidArgument, "parse: %v", err) } + return &connectorv1.ParseResponse{Events: wireEvents(events)}, nil +} + +func wireEvents(events []Event) []*connectorv1.Event { out := make([]*connectorv1.Event, 0, len(events)) for _, e := range events { out = append(out, &connectorv1.Event{ @@ -65,7 +73,43 @@ func (s *server) Parse(ctx context.Context, req *connectorv1.ParseRequest) (*con LinkKey: e.LinkKey, OccurredAt: timestamppb.New(e.OccurredAt), }) } - return &connectorv1.ParseResponse{Events: out}, nil + return out +} + +// Deliver sends one delivery. +func (s *server) Deliver(ctx context.Context, req *connectorv1.DeliverRequest) (*connectorv1.DeliverResponse, error) { + c, err := s.connector() + if err != nil { + return nil, err + } + d, ok := c.(Deliverer) + if !ok { + return nil, status.Error(codes.Unimplemented, "connector has no deliveries") + } + id, err := d.Deliver(ctx, req.GetDelivery(), req.GetInput(), req.GetIdempotencyKey()) + if err != nil { + return nil, status.Errorf(codes.Unknown, "deliver: %v", err) + } + return &connectorv1.DeliverResponse{ExternalId: id}, nil +} + +// Listen streams a listening connector's events until the host hangs up. +func (s *server) Listen(req *connectorv1.ListenRequest, stream connectorv1.ConnectorService_ListenServer) error { + c, err := s.connector() + if err != nil { + return err + } + l, ok := c.(Listener) + if !ok { + return status.Error(codes.Unimplemented, "connector doesn't listen") + } + err = l.Listen(stream.Context(), req.GetCursor(), func(events []Event, cursor string) error { + return stream.Send(&connectorv1.ListenResponse{Events: wireEvents(events), Cursor: cursor}) + }) + if err != nil && stream.Context().Err() == nil { + return status.Errorf(codes.Unavailable, "listen: %v", err) + } + return nil } func (s *server) actor() (Actor, error) { diff --git a/sdk/connector/v1/connector.pb.go b/sdk/connector/v1/connector.pb.go index cadd22c..b660c0b 100644 --- a/sdk/connector/v1/connector.pb.go +++ b/sdk/connector/v1/connector.pb.go @@ -204,10 +204,13 @@ func (*DescribeRequest) Descriptor() ([]byte, []int) { type DescribeResponse struct { state protoimpl.MessageState `protogen:"open.v1"` // contract is the contract version the connector speaks, "v1". - Contract string `protobuf:"bytes,1,opt,name=contract,proto3" json:"contract,omitempty"` - Events []*EventType `protobuf:"bytes,2,rep,name=events,proto3" json:"events,omitempty"` - Actions []*ActionType `protobuf:"bytes,3,rep,name=actions,proto3" json:"actions,omitempty"` - Lookups []*LookupType `protobuf:"bytes,4,rep,name=lookups,proto3" json:"lookups,omitempty"` + Contract string `protobuf:"bytes,1,opt,name=contract,proto3" json:"contract,omitempty"` + Events []*EventType `protobuf:"bytes,2,rep,name=events,proto3" json:"events,omitempty"` + Actions []*ActionType `protobuf:"bytes,3,rep,name=actions,proto3" json:"actions,omitempty"` + Lookups []*LookupType `protobuf:"bytes,4,rep,name=lookups,proto3" json:"lookups,omitempty"` + Deliveries []*DeliveryType `protobuf:"bytes,5,rep,name=deliveries,proto3" json:"deliveries,omitempty"` + // listens says the connector serves Listen. + Listens bool `protobuf:"varint,6,opt,name=listens,proto3" json:"listens,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -270,6 +273,20 @@ func (x *DescribeResponse) GetLookups() []*LookupType { return nil } +func (x *DescribeResponse) GetDeliveries() []*DeliveryType { + if x != nil { + return x.Deliveries + } + return nil +} + +func (x *DescribeResponse) GetListens() bool { + if x != nil { + return x.Listens + } + return false +} + type EventType struct { state protoimpl.MessageState `protogen:"open.v1"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` @@ -412,6 +429,66 @@ func (x *ActionType) GetIdempotent() bool { return false } +type DeliveryType struct { + state protoimpl.MessageState `protogen:"open.v1"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + InputSchema []byte `protobuf:"bytes,3,opt,name=input_schema,json=inputSchema,proto3" json:"input_schema,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DeliveryType) Reset() { + *x = DeliveryType{} + mi := &file_connector_v1_connector_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DeliveryType) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeliveryType) ProtoMessage() {} + +func (x *DeliveryType) ProtoReflect() protoreflect.Message { + mi := &file_connector_v1_connector_proto_msgTypes[6] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeliveryType.ProtoReflect.Descriptor instead. +func (*DeliveryType) Descriptor() ([]byte, []int) { + return file_connector_v1_connector_proto_rawDescGZIP(), []int{6} +} + +func (x *DeliveryType) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *DeliveryType) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *DeliveryType) GetInputSchema() []byte { + if x != nil { + return x.InputSchema + } + return nil +} + type LookupType struct { state protoimpl.MessageState `protogen:"open.v1"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` @@ -423,7 +500,7 @@ type LookupType struct { func (x *LookupType) Reset() { *x = LookupType{} - mi := &file_connector_v1_connector_proto_msgTypes[6] + mi := &file_connector_v1_connector_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -435,7 +512,7 @@ func (x *LookupType) String() string { func (*LookupType) ProtoMessage() {} func (x *LookupType) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[6] + mi := &file_connector_v1_connector_proto_msgTypes[7] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -448,7 +525,7 @@ func (x *LookupType) ProtoReflect() protoreflect.Message { // Deprecated: Use LookupType.ProtoReflect.Descriptor instead. func (*LookupType) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{6} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{7} } func (x *LookupType) GetName() string { @@ -485,7 +562,7 @@ type Effect struct { func (x *Effect) Reset() { *x = Effect{} - mi := &file_connector_v1_connector_proto_msgTypes[7] + mi := &file_connector_v1_connector_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -497,7 +574,7 @@ func (x *Effect) String() string { func (*Effect) ProtoMessage() {} func (x *Effect) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[7] + mi := &file_connector_v1_connector_proto_msgTypes[8] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -510,7 +587,7 @@ func (x *Effect) ProtoReflect() protoreflect.Message { // Deprecated: Use Effect.ProtoReflect.Descriptor instead. func (*Effect) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{7} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{8} } func (x *Effect) GetReadOnly() bool { @@ -548,7 +625,7 @@ type Target struct { func (x *Target) Reset() { *x = Target{} - mi := &file_connector_v1_connector_proto_msgTypes[8] + mi := &file_connector_v1_connector_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -560,7 +637,7 @@ func (x *Target) String() string { func (*Target) ProtoMessage() {} func (x *Target) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[8] + mi := &file_connector_v1_connector_proto_msgTypes[9] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -573,7 +650,7 @@ func (x *Target) ProtoReflect() protoreflect.Message { // Deprecated: Use Target.ProtoReflect.Descriptor instead. func (*Target) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{8} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{9} } func (x *Target) GetKind() string { @@ -614,7 +691,7 @@ type ParseRequest struct { func (x *ParseRequest) Reset() { *x = ParseRequest{} - mi := &file_connector_v1_connector_proto_msgTypes[9] + mi := &file_connector_v1_connector_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -626,7 +703,7 @@ func (x *ParseRequest) String() string { func (*ParseRequest) ProtoMessage() {} func (x *ParseRequest) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[9] + mi := &file_connector_v1_connector_proto_msgTypes[10] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -639,7 +716,7 @@ func (x *ParseRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ParseRequest.ProtoReflect.Descriptor instead. func (*ParseRequest) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{9} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{10} } func (x *ParseRequest) GetBody() []byte { @@ -665,7 +742,7 @@ type ParseResponse struct { func (x *ParseResponse) Reset() { *x = ParseResponse{} - mi := &file_connector_v1_connector_proto_msgTypes[10] + mi := &file_connector_v1_connector_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -677,7 +754,7 @@ func (x *ParseResponse) String() string { func (*ParseResponse) ProtoMessage() {} func (x *ParseResponse) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[10] + mi := &file_connector_v1_connector_proto_msgTypes[11] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -690,7 +767,7 @@ func (x *ParseResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ParseResponse.ProtoReflect.Descriptor instead. func (*ParseResponse) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{10} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{11} } func (x *ParseResponse) GetEvents() []*Event { @@ -717,7 +794,7 @@ type Event struct { func (x *Event) Reset() { *x = Event{} - mi := &file_connector_v1_connector_proto_msgTypes[11] + mi := &file_connector_v1_connector_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -729,7 +806,7 @@ func (x *Event) String() string { func (*Event) ProtoMessage() {} func (x *Event) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[11] + mi := &file_connector_v1_connector_proto_msgTypes[12] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -742,7 +819,7 @@ func (x *Event) ProtoReflect() protoreflect.Message { // Deprecated: Use Event.ProtoReflect.Descriptor instead. func (*Event) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{11} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{12} } func (x *Event) GetType() string { @@ -790,7 +867,7 @@ type ResolveRequest struct { func (x *ResolveRequest) Reset() { *x = ResolveRequest{} - mi := &file_connector_v1_connector_proto_msgTypes[12] + mi := &file_connector_v1_connector_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -802,7 +879,7 @@ func (x *ResolveRequest) String() string { func (*ResolveRequest) ProtoMessage() {} func (x *ResolveRequest) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[12] + mi := &file_connector_v1_connector_proto_msgTypes[13] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -815,7 +892,7 @@ func (x *ResolveRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ResolveRequest.ProtoReflect.Descriptor instead. func (*ResolveRequest) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{12} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{13} } func (x *ResolveRequest) GetAction() string { @@ -842,7 +919,7 @@ type ResolveResponse struct { func (x *ResolveResponse) Reset() { *x = ResolveResponse{} - mi := &file_connector_v1_connector_proto_msgTypes[13] + mi := &file_connector_v1_connector_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -854,7 +931,7 @@ func (x *ResolveResponse) String() string { func (*ResolveResponse) ProtoMessage() {} func (x *ResolveResponse) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[13] + mi := &file_connector_v1_connector_proto_msgTypes[14] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -867,7 +944,7 @@ func (x *ResolveResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ResolveResponse.ProtoReflect.Descriptor instead. func (*ResolveResponse) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{13} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{14} } func (x *ResolveResponse) GetTarget() *Target { @@ -897,7 +974,7 @@ type InvokeRequest struct { func (x *InvokeRequest) Reset() { *x = InvokeRequest{} - mi := &file_connector_v1_connector_proto_msgTypes[14] + mi := &file_connector_v1_connector_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -909,7 +986,7 @@ func (x *InvokeRequest) String() string { func (*InvokeRequest) ProtoMessage() {} func (x *InvokeRequest) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[14] + mi := &file_connector_v1_connector_proto_msgTypes[15] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -922,7 +999,7 @@ func (x *InvokeRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use InvokeRequest.ProtoReflect.Descriptor instead. func (*InvokeRequest) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{14} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{15} } func (x *InvokeRequest) GetAction() string { @@ -967,7 +1044,7 @@ type InvokeResponse struct { func (x *InvokeResponse) Reset() { *x = InvokeResponse{} - mi := &file_connector_v1_connector_proto_msgTypes[15] + mi := &file_connector_v1_connector_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -979,7 +1056,7 @@ func (x *InvokeResponse) String() string { func (*InvokeResponse) ProtoMessage() {} func (x *InvokeResponse) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[15] + mi := &file_connector_v1_connector_proto_msgTypes[16] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -992,7 +1069,7 @@ func (x *InvokeResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use InvokeResponse.ProtoReflect.Descriptor instead. func (*InvokeResponse) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{15} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{16} } func (x *InvokeResponse) GetOutput() []byte { @@ -1026,7 +1103,7 @@ type LookupRequest struct { func (x *LookupRequest) Reset() { *x = LookupRequest{} - mi := &file_connector_v1_connector_proto_msgTypes[16] + mi := &file_connector_v1_connector_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1038,7 +1115,7 @@ func (x *LookupRequest) String() string { func (*LookupRequest) ProtoMessage() {} func (x *LookupRequest) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[16] + mi := &file_connector_v1_connector_proto_msgTypes[17] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1051,7 +1128,7 @@ func (x *LookupRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use LookupRequest.ProtoReflect.Descriptor instead. func (*LookupRequest) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{16} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{17} } func (x *LookupRequest) GetLookup() string { @@ -1078,7 +1155,7 @@ type LookupResponse struct { func (x *LookupResponse) Reset() { *x = LookupResponse{} - mi := &file_connector_v1_connector_proto_msgTypes[17] + mi := &file_connector_v1_connector_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1090,7 +1167,7 @@ func (x *LookupResponse) String() string { func (*LookupResponse) ProtoMessage() {} func (x *LookupResponse) ProtoReflect() protoreflect.Message { - mi := &file_connector_v1_connector_proto_msgTypes[17] + mi := &file_connector_v1_connector_proto_msgTypes[18] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1103,7 +1180,7 @@ func (x *LookupResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use LookupResponse.ProtoReflect.Descriptor instead. func (*LookupResponse) Descriptor() ([]byte, []int) { - return file_connector_v1_connector_proto_rawDescGZIP(), []int{17} + return file_connector_v1_connector_proto_rawDescGZIP(), []int{18} } func (x *LookupResponse) GetOutput() []byte { @@ -1120,6 +1197,208 @@ func (x *LookupResponse) GetFound() bool { return false } +type DeliverRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Delivery string `protobuf:"bytes,1,opt,name=delivery,proto3" json:"delivery,omitempty"` + Input []byte `protobuf:"bytes,2,opt,name=input,proto3" json:"input,omitempty"` + IdempotencyKey string `protobuf:"bytes,3,opt,name=idempotency_key,json=idempotencyKey,proto3" json:"idempotency_key,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DeliverRequest) Reset() { + *x = DeliverRequest{} + mi := &file_connector_v1_connector_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DeliverRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeliverRequest) ProtoMessage() {} + +func (x *DeliverRequest) ProtoReflect() protoreflect.Message { + mi := &file_connector_v1_connector_proto_msgTypes[19] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeliverRequest.ProtoReflect.Descriptor instead. +func (*DeliverRequest) Descriptor() ([]byte, []int) { + return file_connector_v1_connector_proto_rawDescGZIP(), []int{19} +} + +func (x *DeliverRequest) GetDelivery() string { + if x != nil { + return x.Delivery + } + return "" +} + +func (x *DeliverRequest) GetInput() []byte { + if x != nil { + return x.Input + } + return nil +} + +func (x *DeliverRequest) GetIdempotencyKey() string { + if x != nil { + return x.IdempotencyKey + } + return "" +} + +type DeliverResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + // external_id is what the service called what was delivered, for linking. + ExternalId string `protobuf:"bytes,1,opt,name=external_id,json=externalId,proto3" json:"external_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DeliverResponse) Reset() { + *x = DeliverResponse{} + mi := &file_connector_v1_connector_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DeliverResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeliverResponse) ProtoMessage() {} + +func (x *DeliverResponse) ProtoReflect() protoreflect.Message { + mi := &file_connector_v1_connector_proto_msgTypes[20] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeliverResponse.ProtoReflect.Descriptor instead. +func (*DeliverResponse) Descriptor() ([]byte, []int) { + return file_connector_v1_connector_proto_rawDescGZIP(), []int{20} +} + +func (x *DeliverResponse) GetExternalId() string { + if x != nil { + return x.ExternalId + } + return "" +} + +type ListenRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // cursor is the last cursor the host stored, empty from the start. + Cursor string `protobuf:"bytes,1,opt,name=cursor,proto3" json:"cursor,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ListenRequest) Reset() { + *x = ListenRequest{} + mi := &file_connector_v1_connector_proto_msgTypes[21] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ListenRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListenRequest) ProtoMessage() {} + +func (x *ListenRequest) ProtoReflect() protoreflect.Message { + mi := &file_connector_v1_connector_proto_msgTypes[21] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListenRequest.ProtoReflect.Descriptor instead. +func (*ListenRequest) Descriptor() ([]byte, []int) { + return file_connector_v1_connector_proto_rawDescGZIP(), []int{21} +} + +func (x *ListenRequest) GetCursor() string { + if x != nil { + return x.Cursor + } + return "" +} + +type ListenResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Events []*Event `protobuf:"bytes,1,rep,name=events,proto3" json:"events,omitempty"` + Cursor string `protobuf:"bytes,2,opt,name=cursor,proto3" json:"cursor,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ListenResponse) Reset() { + *x = ListenResponse{} + mi := &file_connector_v1_connector_proto_msgTypes[22] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ListenResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListenResponse) ProtoMessage() {} + +func (x *ListenResponse) ProtoReflect() protoreflect.Message { + mi := &file_connector_v1_connector_proto_msgTypes[22] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListenResponse.ProtoReflect.Descriptor instead. +func (*ListenResponse) Descriptor() ([]byte, []int) { + return file_connector_v1_connector_proto_rawDescGZIP(), []int{22} +} + +func (x *ListenResponse) GetEvents() []*Event { + if x != nil { + return x.Events + } + return nil +} + +func (x *ListenResponse) GetCursor() string { + if x != nil { + return x.Cursor + } + return "" +} + var File_connector_v1_connector_proto protoreflect.FileDescriptor const file_connector_v1_connector_proto_rawDesc = "" + @@ -1135,12 +1414,16 @@ const file_connector_v1_connector_proto_rawDesc = "" + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"\x13\n" + "\x11ConfigureResponse\"\x11\n" + - "\x0fDescribeRequest\"\xc7\x01\n" + + "\x0fDescribeRequest\"\x9d\x02\n" + "\x10DescribeResponse\x12\x1a\n" + "\bcontract\x18\x01 \x01(\tR\bcontract\x12/\n" + "\x06events\x18\x02 \x03(\v2\x17.connector.v1.EventTypeR\x06events\x122\n" + "\aactions\x18\x03 \x03(\v2\x18.connector.v1.ActionTypeR\aactions\x122\n" + - "\alookups\x18\x04 \x03(\v2\x18.connector.v1.LookupTypeR\alookups\"Y\n" + + "\alookups\x18\x04 \x03(\v2\x18.connector.v1.LookupTypeR\alookups\x12:\n" + + "\n" + + "deliveries\x18\x05 \x03(\v2\x1a.connector.v1.DeliveryTypeR\n" + + "deliveries\x12\x18\n" + + "\alistens\x18\x06 \x01(\bR\alistens\"Y\n" + "\tEventType\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12 \n" + "\vdescription\x18\x02 \x01(\tR\vdescription\x12\x16\n" + @@ -1153,7 +1436,11 @@ const file_connector_v1_connector_proto_rawDesc = "" + "\x06effect\x18\x04 \x01(\v2\x14.connector.v1.EffectR\x06effect\x12\x1e\n" + "\n" + "idempotent\x18\x05 \x01(\bR\n" + - "idempotent\"e\n" + + "idempotent\"g\n" + + "\fDeliveryType\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name\x12 \n" + + "\vdescription\x18\x02 \x01(\tR\vdescription\x12!\n" + + "\finput_schema\x18\x03 \x01(\fR\vinputSchema\"e\n" + "\n" + "LookupType\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12 \n" + @@ -1205,19 +1492,33 @@ const file_connector_v1_connector_proto_rawDesc = "" + "\x05input\x18\x02 \x01(\fR\x05input\">\n" + "\x0eLookupResponse\x12\x16\n" + "\x06output\x18\x01 \x01(\fR\x06output\x12\x14\n" + - "\x05found\x18\x02 \x01(\bR\x05found*\x95\x01\n" + + "\x05found\x18\x02 \x01(\bR\x05found\"k\n" + + "\x0eDeliverRequest\x12\x1a\n" + + "\bdelivery\x18\x01 \x01(\tR\bdelivery\x12\x14\n" + + "\x05input\x18\x02 \x01(\fR\x05input\x12'\n" + + "\x0fidempotency_key\x18\x03 \x01(\tR\x0eidempotencyKey\"2\n" + + "\x0fDeliverResponse\x12\x1f\n" + + "\vexternal_id\x18\x01 \x01(\tR\n" + + "externalId\"'\n" + + "\rListenRequest\x12\x16\n" + + "\x06cursor\x18\x01 \x01(\tR\x06cursor\"U\n" + + "\x0eListenResponse\x12+\n" + + "\x06events\x18\x01 \x03(\v2\x13.connector.v1.EventR\x06events\x12\x16\n" + + "\x06cursor\x18\x02 \x01(\tR\x06cursor*\x95\x01\n" + "\rReversibility\x12\x1d\n" + "\x19REVERSIBILITY_UNSPECIFIED\x10\x00\x12&\n" + "\"REVERSIBILITY_UNDONE_AUTOMATICALLY\x10\x01\x12\x1d\n" + "\x19REVERSIBILITY_RECOVERABLE\x10\x02\x12\x1e\n" + - "\x1aREVERSIBILITY_IRREVERSIBLE\x10\x032\xbf\x03\n" + + "\x1aREVERSIBILITY_IRREVERSIBLE\x10\x032\xce\x04\n" + "\x10ConnectorService\x12L\n" + "\tConfigure\x12\x1e.connector.v1.ConfigureRequest\x1a\x1f.connector.v1.ConfigureResponse\x12I\n" + "\bDescribe\x12\x1d.connector.v1.DescribeRequest\x1a\x1e.connector.v1.DescribeResponse\x12@\n" + "\x05Parse\x12\x1a.connector.v1.ParseRequest\x1a\x1b.connector.v1.ParseResponse\x12F\n" + "\aResolve\x12\x1c.connector.v1.ResolveRequest\x1a\x1d.connector.v1.ResolveResponse\x12C\n" + "\x06Invoke\x12\x1b.connector.v1.InvokeRequest\x1a\x1c.connector.v1.InvokeResponse\x12C\n" + - "\x06Lookup\x12\x1b.connector.v1.LookupRequest\x1a\x1c.connector.v1.LookupResponseB\xb5\x01\n" + + "\x06Lookup\x12\x1b.connector.v1.LookupRequest\x1a\x1c.connector.v1.LookupResponse\x12F\n" + + "\aDeliver\x12\x1c.connector.v1.DeliverRequest\x1a\x1d.connector.v1.DeliverResponse\x12E\n" + + "\x06Listen\x12\x1b.connector.v1.ListenRequest\x1a\x1c.connector.v1.ListenResponse0\x01B\xb5\x01\n" + "\x10com.connector.v1B\x0eConnectorProtoP\x01Z@github.com/samcharles93/archipelago/sdk/connector/v1;connectorv1\xa2\x02\x03CXX\xaa\x02\fConnector.V1\xca\x02\fConnector\\V1\xe2\x02\x18Connector\\V1\\GPBMetadata\xea\x02\rConnector::V1b\x06proto3" var ( @@ -1233,7 +1534,7 @@ func file_connector_v1_connector_proto_rawDescGZIP() []byte { } var file_connector_v1_connector_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_connector_v1_connector_proto_msgTypes = make([]protoimpl.MessageInfo, 21) +var file_connector_v1_connector_proto_msgTypes = make([]protoimpl.MessageInfo, 26) var file_connector_v1_connector_proto_goTypes = []any{ (Reversibility)(0), // 0: connector.v1.Reversibility (*ConfigureRequest)(nil), // 1: connector.v1.ConfigureRequest @@ -1242,53 +1543,64 @@ var file_connector_v1_connector_proto_goTypes = []any{ (*DescribeResponse)(nil), // 4: connector.v1.DescribeResponse (*EventType)(nil), // 5: connector.v1.EventType (*ActionType)(nil), // 6: connector.v1.ActionType - (*LookupType)(nil), // 7: connector.v1.LookupType - (*Effect)(nil), // 8: connector.v1.Effect - (*Target)(nil), // 9: connector.v1.Target - (*ParseRequest)(nil), // 10: connector.v1.ParseRequest - (*ParseResponse)(nil), // 11: connector.v1.ParseResponse - (*Event)(nil), // 12: connector.v1.Event - (*ResolveRequest)(nil), // 13: connector.v1.ResolveRequest - (*ResolveResponse)(nil), // 14: connector.v1.ResolveResponse - (*InvokeRequest)(nil), // 15: connector.v1.InvokeRequest - (*InvokeResponse)(nil), // 16: connector.v1.InvokeResponse - (*LookupRequest)(nil), // 17: connector.v1.LookupRequest - (*LookupResponse)(nil), // 18: connector.v1.LookupResponse - nil, // 19: connector.v1.ConfigureRequest.SettingsEntry - nil, // 20: connector.v1.ConfigureRequest.SecretsEntry - nil, // 21: connector.v1.ParseRequest.HeadersEntry - (*timestamppb.Timestamp)(nil), // 22: google.protobuf.Timestamp + (*DeliveryType)(nil), // 7: connector.v1.DeliveryType + (*LookupType)(nil), // 8: connector.v1.LookupType + (*Effect)(nil), // 9: connector.v1.Effect + (*Target)(nil), // 10: connector.v1.Target + (*ParseRequest)(nil), // 11: connector.v1.ParseRequest + (*ParseResponse)(nil), // 12: connector.v1.ParseResponse + (*Event)(nil), // 13: connector.v1.Event + (*ResolveRequest)(nil), // 14: connector.v1.ResolveRequest + (*ResolveResponse)(nil), // 15: connector.v1.ResolveResponse + (*InvokeRequest)(nil), // 16: connector.v1.InvokeRequest + (*InvokeResponse)(nil), // 17: connector.v1.InvokeResponse + (*LookupRequest)(nil), // 18: connector.v1.LookupRequest + (*LookupResponse)(nil), // 19: connector.v1.LookupResponse + (*DeliverRequest)(nil), // 20: connector.v1.DeliverRequest + (*DeliverResponse)(nil), // 21: connector.v1.DeliverResponse + (*ListenRequest)(nil), // 22: connector.v1.ListenRequest + (*ListenResponse)(nil), // 23: connector.v1.ListenResponse + nil, // 24: connector.v1.ConfigureRequest.SettingsEntry + nil, // 25: connector.v1.ConfigureRequest.SecretsEntry + nil, // 26: connector.v1.ParseRequest.HeadersEntry + (*timestamppb.Timestamp)(nil), // 27: google.protobuf.Timestamp } var file_connector_v1_connector_proto_depIdxs = []int32{ - 19, // 0: connector.v1.ConfigureRequest.settings:type_name -> connector.v1.ConfigureRequest.SettingsEntry - 20, // 1: connector.v1.ConfigureRequest.secrets:type_name -> connector.v1.ConfigureRequest.SecretsEntry + 24, // 0: connector.v1.ConfigureRequest.settings:type_name -> connector.v1.ConfigureRequest.SettingsEntry + 25, // 1: connector.v1.ConfigureRequest.secrets:type_name -> connector.v1.ConfigureRequest.SecretsEntry 5, // 2: connector.v1.DescribeResponse.events:type_name -> connector.v1.EventType 6, // 3: connector.v1.DescribeResponse.actions:type_name -> connector.v1.ActionType - 7, // 4: connector.v1.DescribeResponse.lookups:type_name -> connector.v1.LookupType - 8, // 5: connector.v1.ActionType.effect:type_name -> connector.v1.Effect - 0, // 6: connector.v1.Effect.reversibility:type_name -> connector.v1.Reversibility - 21, // 7: connector.v1.ParseRequest.headers:type_name -> connector.v1.ParseRequest.HeadersEntry - 12, // 8: connector.v1.ParseResponse.events:type_name -> connector.v1.Event - 22, // 9: connector.v1.Event.occurred_at:type_name -> google.protobuf.Timestamp - 9, // 10: connector.v1.ResolveResponse.target:type_name -> connector.v1.Target - 8, // 11: connector.v1.ResolveResponse.effect:type_name -> connector.v1.Effect - 1, // 12: connector.v1.ConnectorService.Configure:input_type -> connector.v1.ConfigureRequest - 3, // 13: connector.v1.ConnectorService.Describe:input_type -> connector.v1.DescribeRequest - 10, // 14: connector.v1.ConnectorService.Parse:input_type -> connector.v1.ParseRequest - 13, // 15: connector.v1.ConnectorService.Resolve:input_type -> connector.v1.ResolveRequest - 15, // 16: connector.v1.ConnectorService.Invoke:input_type -> connector.v1.InvokeRequest - 17, // 17: connector.v1.ConnectorService.Lookup:input_type -> connector.v1.LookupRequest - 2, // 18: connector.v1.ConnectorService.Configure:output_type -> connector.v1.ConfigureResponse - 4, // 19: connector.v1.ConnectorService.Describe:output_type -> connector.v1.DescribeResponse - 11, // 20: connector.v1.ConnectorService.Parse:output_type -> connector.v1.ParseResponse - 14, // 21: connector.v1.ConnectorService.Resolve:output_type -> connector.v1.ResolveResponse - 16, // 22: connector.v1.ConnectorService.Invoke:output_type -> connector.v1.InvokeResponse - 18, // 23: connector.v1.ConnectorService.Lookup:output_type -> connector.v1.LookupResponse - 18, // [18:24] is the sub-list for method output_type - 12, // [12:18] is the sub-list for method input_type - 12, // [12:12] is the sub-list for extension type_name - 12, // [12:12] is the sub-list for extension extendee - 0, // [0:12] is the sub-list for field type_name + 8, // 4: connector.v1.DescribeResponse.lookups:type_name -> connector.v1.LookupType + 7, // 5: connector.v1.DescribeResponse.deliveries:type_name -> connector.v1.DeliveryType + 9, // 6: connector.v1.ActionType.effect:type_name -> connector.v1.Effect + 0, // 7: connector.v1.Effect.reversibility:type_name -> connector.v1.Reversibility + 26, // 8: connector.v1.ParseRequest.headers:type_name -> connector.v1.ParseRequest.HeadersEntry + 13, // 9: connector.v1.ParseResponse.events:type_name -> connector.v1.Event + 27, // 10: connector.v1.Event.occurred_at:type_name -> google.protobuf.Timestamp + 10, // 11: connector.v1.ResolveResponse.target:type_name -> connector.v1.Target + 9, // 12: connector.v1.ResolveResponse.effect:type_name -> connector.v1.Effect + 13, // 13: connector.v1.ListenResponse.events:type_name -> connector.v1.Event + 1, // 14: connector.v1.ConnectorService.Configure:input_type -> connector.v1.ConfigureRequest + 3, // 15: connector.v1.ConnectorService.Describe:input_type -> connector.v1.DescribeRequest + 11, // 16: connector.v1.ConnectorService.Parse:input_type -> connector.v1.ParseRequest + 14, // 17: connector.v1.ConnectorService.Resolve:input_type -> connector.v1.ResolveRequest + 16, // 18: connector.v1.ConnectorService.Invoke:input_type -> connector.v1.InvokeRequest + 18, // 19: connector.v1.ConnectorService.Lookup:input_type -> connector.v1.LookupRequest + 20, // 20: connector.v1.ConnectorService.Deliver:input_type -> connector.v1.DeliverRequest + 22, // 21: connector.v1.ConnectorService.Listen:input_type -> connector.v1.ListenRequest + 2, // 22: connector.v1.ConnectorService.Configure:output_type -> connector.v1.ConfigureResponse + 4, // 23: connector.v1.ConnectorService.Describe:output_type -> connector.v1.DescribeResponse + 12, // 24: connector.v1.ConnectorService.Parse:output_type -> connector.v1.ParseResponse + 15, // 25: connector.v1.ConnectorService.Resolve:output_type -> connector.v1.ResolveResponse + 17, // 26: connector.v1.ConnectorService.Invoke:output_type -> connector.v1.InvokeResponse + 19, // 27: connector.v1.ConnectorService.Lookup:output_type -> connector.v1.LookupResponse + 21, // 28: connector.v1.ConnectorService.Deliver:output_type -> connector.v1.DeliverResponse + 23, // 29: connector.v1.ConnectorService.Listen:output_type -> connector.v1.ListenResponse + 22, // [22:30] is the sub-list for method output_type + 14, // [14:22] is the sub-list for method input_type + 14, // [14:14] is the sub-list for extension type_name + 14, // [14:14] is the sub-list for extension extendee + 0, // [0:14] is the sub-list for field type_name } func init() { file_connector_v1_connector_proto_init() } @@ -1302,7 +1614,7 @@ func file_connector_v1_connector_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_connector_v1_connector_proto_rawDesc), len(file_connector_v1_connector_proto_rawDesc)), NumEnums: 1, - NumMessages: 21, + NumMessages: 26, NumExtensions: 0, NumServices: 1, }, diff --git a/sdk/connector/v1/connector_grpc.pb.go b/sdk/connector/v1/connector_grpc.pb.go index dea90db..fc347be 100644 --- a/sdk/connector/v1/connector_grpc.pb.go +++ b/sdk/connector/v1/connector_grpc.pb.go @@ -25,6 +25,8 @@ const ( ConnectorService_Resolve_FullMethodName = "/connector.v1.ConnectorService/Resolve" ConnectorService_Invoke_FullMethodName = "/connector.v1.ConnectorService/Invoke" ConnectorService_Lookup_FullMethodName = "/connector.v1.ConnectorService/Lookup" + ConnectorService_Deliver_FullMethodName = "/connector.v1.ConnectorService/Deliver" + ConnectorService_Listen_FullMethodName = "/connector.v1.ConnectorService/Listen" ) // ConnectorServiceClient is the client API for ConnectorService service. @@ -53,6 +55,16 @@ type ConnectorServiceClient interface { // Lookup answers a read-only question. Lookups change nothing and run no // guards; a lookup that finds nothing says so. Lookup(ctx context.Context, in *LookupRequest, opts ...grpc.CallOption) (*LookupResponse, error) + // Deliver sends a message or record to people or a system of record. A + // delivery is never offered to an agent: hard rules apply to it, guards + // don't. The host retries a failed delivery, so a connector should make a + // repeat with the same idempotency key harmless where its service allows. + Deliver(ctx context.Context, in *DeliverRequest, opts ...grpc.CallOption) (*DeliverResponse, error) + // Listen streams the events of a source the connector holds its own + // connection to, such as a chat long poll, from cursor on. Each response + // carries the cursor to resume after its events, which the host keeps only + // once those events are stored. + Listen(ctx context.Context, in *ListenRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ListenResponse], error) } type connectorServiceClient struct { @@ -123,6 +135,35 @@ func (c *connectorServiceClient) Lookup(ctx context.Context, in *LookupRequest, return out, nil } +func (c *connectorServiceClient) Deliver(ctx context.Context, in *DeliverRequest, opts ...grpc.CallOption) (*DeliverResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(DeliverResponse) + err := c.cc.Invoke(ctx, ConnectorService_Deliver_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *connectorServiceClient) Listen(ctx context.Context, in *ListenRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ListenResponse], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &ConnectorService_ServiceDesc.Streams[0], ConnectorService_Listen_FullMethodName, cOpts...) + if err != nil { + return nil, err + } + x := &grpc.GenericClientStream[ListenRequest, ListenResponse]{ClientStream: stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type ConnectorService_ListenClient = grpc.ServerStreamingClient[ListenResponse] + // ConnectorServiceServer is the server API for ConnectorService service. // All implementations must embed UnimplementedConnectorServiceServer // for forward compatibility. @@ -149,6 +190,16 @@ type ConnectorServiceServer interface { // Lookup answers a read-only question. Lookups change nothing and run no // guards; a lookup that finds nothing says so. Lookup(context.Context, *LookupRequest) (*LookupResponse, error) + // Deliver sends a message or record to people or a system of record. A + // delivery is never offered to an agent: hard rules apply to it, guards + // don't. The host retries a failed delivery, so a connector should make a + // repeat with the same idempotency key harmless where its service allows. + Deliver(context.Context, *DeliverRequest) (*DeliverResponse, error) + // Listen streams the events of a source the connector holds its own + // connection to, such as a chat long poll, from cursor on. Each response + // carries the cursor to resume after its events, which the host keeps only + // once those events are stored. + Listen(*ListenRequest, grpc.ServerStreamingServer[ListenResponse]) error mustEmbedUnimplementedConnectorServiceServer() } @@ -177,6 +228,12 @@ func (UnimplementedConnectorServiceServer) Invoke(context.Context, *InvokeReques func (UnimplementedConnectorServiceServer) Lookup(context.Context, *LookupRequest) (*LookupResponse, error) { return nil, status.Error(codes.Unimplemented, "method Lookup not implemented") } +func (UnimplementedConnectorServiceServer) Deliver(context.Context, *DeliverRequest) (*DeliverResponse, error) { + return nil, status.Error(codes.Unimplemented, "method Deliver not implemented") +} +func (UnimplementedConnectorServiceServer) Listen(*ListenRequest, grpc.ServerStreamingServer[ListenResponse]) error { + return status.Error(codes.Unimplemented, "method Listen not implemented") +} func (UnimplementedConnectorServiceServer) mustEmbedUnimplementedConnectorServiceServer() {} func (UnimplementedConnectorServiceServer) testEmbeddedByValue() {} @@ -306,6 +363,35 @@ func _ConnectorService_Lookup_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +func _ConnectorService_Deliver_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeliverRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConnectorServiceServer).Deliver(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ConnectorService_Deliver_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConnectorServiceServer).Deliver(ctx, req.(*DeliverRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ConnectorService_Listen_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(ListenRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(ConnectorServiceServer).Listen(m, &grpc.GenericServerStream[ListenRequest, ListenResponse]{ServerStream: stream}) +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type ConnectorService_ListenServer = grpc.ServerStreamingServer[ListenResponse] + // ConnectorService_ServiceDesc is the grpc.ServiceDesc for ConnectorService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -337,7 +423,17 @@ var ConnectorService_ServiceDesc = grpc.ServiceDesc{ MethodName: "Lookup", Handler: _ConnectorService_Lookup_Handler, }, + { + MethodName: "Deliver", + Handler: _ConnectorService_Deliver_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "Listen", + Handler: _ConnectorService_Listen_Handler, + ServerStreams: true, + }, }, - Streams: []grpc.StreamDesc{}, Metadata: "connector/v1/connector.proto", }