From 2ddcc28b1af4823b85225314ddc86d05b800b15f Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sun, 22 Nov 2026 02:15:47 +1100 Subject: [PATCH] feat(sdk): let a connector declare it links accounts and serve LinkURL (archie-core #2095) Regenerate the connector SDK from the host contract, which adds links_accounts and the LinkURL RPC. A connector that implements Linker declares it. --- sdk/connector/connector.go | 8 ++ sdk/connector/server.go | 20 +++- sdk/connector/v1/connector.pb.go | 165 +++++++++++++++++++++----- sdk/connector/v1/connector_grpc.pb.go | 48 ++++++++ 4 files changed, 213 insertions(+), 28 deletions(-) diff --git a/sdk/connector/connector.go b/sdk/connector/connector.go index 898734c..bd23ee5 100644 --- a/sdk/connector/connector.go +++ b/sdk/connector/connector.go @@ -100,6 +100,14 @@ type Listener interface { Listen(ctx context.Context, cursor string, emit func(events []Event, cursor string) error) error } +// Linker lets a person link their channel identity to an account. LinkURL +// returns the URL that delivers a link code to the connector, which then emits +// an account.link event carrying the code and the sender's identity. Its +// events name the sender in "by" as ":". +type Linker interface { + LinkURL(ctx context.Context, code string) (string, 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 33d3bb8..28008f5 100644 --- a/sdk/connector/server.go +++ b/sdk/connector/server.go @@ -43,9 +43,10 @@ func (s *server) Describe(context.Context, *connectorv1.DescribeRequest) (*conne } d := c.Describe() _, listens := c.(Listener) + _, links := c.(Linker) return &connectorv1.DescribeResponse{ Contract: Contract, Events: d.Events, Actions: d.Actions, Lookups: d.Lookups, - Deliveries: d.Deliveries, Listens: listens, + Deliveries: d.Deliveries, Listens: listens, LinksAccounts: links, }, nil } @@ -170,3 +171,20 @@ func (s *server) Lookup(ctx context.Context, req *connectorv1.LookupRequest) (*c } return &connectorv1.LookupResponse{Output: out, Found: found}, nil } + +// LinkURL returns the URL a person opens to send a link code to the connector. +func (s *server) LinkURL(ctx context.Context, req *connectorv1.LinkURLRequest) (*connectorv1.LinkURLResponse, error) { + c, err := s.connector() + if err != nil { + return nil, err + } + l, ok := c.(Linker) + if !ok { + return nil, status.Error(codes.Unimplemented, "connector doesn't link accounts") + } + url, err := l.LinkURL(ctx, req.GetCode()) + if err != nil { + return nil, status.Errorf(codes.Unavailable, "link URL: %v", err) + } + return &connectorv1.LinkURLResponse{Url: url}, nil +} diff --git a/sdk/connector/v1/connector.pb.go b/sdk/connector/v1/connector.pb.go index c1ad1ec..2a1b598 100644 --- a/sdk/connector/v1/connector.pb.go +++ b/sdk/connector/v1/connector.pb.go @@ -281,7 +281,10 @@ type DescribeResponse struct { // which the dashboard renders as a form. Settings []*Setting `protobuf:"bytes,8,rep,name=settings,proto3" json:"settings,omitempty"` // version is the connector's own release. - Version string `protobuf:"bytes,9,opt,name=version,proto3" json:"version,omitempty"` + Version string `protobuf:"bytes,9,opt,name=version,proto3" json:"version,omitempty"` + // links_accounts says the connector serves LinkURL and emits account.link + // events, so a person can link their channel identity to an account. + LinksAccounts bool `protobuf:"varint,10,opt,name=links_accounts,json=linksAccounts,proto3" json:"links_accounts,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -379,6 +382,13 @@ func (x *DescribeResponse) GetVersion() string { return "" } +func (x *DescribeResponse) GetLinksAccounts() bool { + if x != nil { + return x.LinksAccounts + } + return false +} + // Setting is one value an operator enters for an extension to run. type Setting struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -1746,6 +1756,96 @@ func (x *ListenResponse) GetCursor() string { return "" } +type LinkURLRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // code is the single-use link code the person sends to the connector. + Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LinkURLRequest) Reset() { + *x = LinkURLRequest{} + mi := &file_connector_v1_connector_proto_msgTypes[26] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LinkURLRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LinkURLRequest) ProtoMessage() {} + +func (x *LinkURLRequest) ProtoReflect() protoreflect.Message { + mi := &file_connector_v1_connector_proto_msgTypes[26] + 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 LinkURLRequest.ProtoReflect.Descriptor instead. +func (*LinkURLRequest) Descriptor() ([]byte, []int) { + return file_connector_v1_connector_proto_rawDescGZIP(), []int{26} +} + +func (x *LinkURLRequest) GetCode() string { + if x != nil { + return x.Code + } + return "" +} + +type LinkURLResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + // url opens the connector's channel with the code attached. + Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LinkURLResponse) Reset() { + *x = LinkURLResponse{} + mi := &file_connector_v1_connector_proto_msgTypes[27] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LinkURLResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LinkURLResponse) ProtoMessage() {} + +func (x *LinkURLResponse) ProtoReflect() protoreflect.Message { + mi := &file_connector_v1_connector_proto_msgTypes[27] + 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 LinkURLResponse.ProtoReflect.Descriptor instead. +func (*LinkURLResponse) Descriptor() ([]byte, []int) { + return file_connector_v1_connector_proto_rawDescGZIP(), []int{27} +} + +func (x *LinkURLResponse) GetUrl() string { + if x != nil { + return x.Url + } + return "" +} + var File_connector_v1_connector_proto protoreflect.FileDescriptor const file_connector_v1_connector_proto_rawDesc = "" + @@ -1761,7 +1861,7 @@ 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\"\x8d\x03\n" + + "\x0fDescribeRequest\"\xb4\x03\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" + @@ -1773,7 +1873,9 @@ const file_connector_v1_connector_proto_rawDesc = "" + "\alistens\x18\x06 \x01(\bR\alistens\x12!\n" + "\ftarget_facts\x18\a \x01(\bR\vtargetFacts\x121\n" + "\bsettings\x18\b \x03(\v2\x15.connector.v1.SettingR\bsettings\x12\x18\n" + - "\aversion\x18\t \x01(\tR\aversion\"\xd0\x01\n" + + "\aversion\x18\t \x01(\tR\aversion\x12%\n" + + "\x0elinks_accounts\x18\n" + + " \x01(\bR\rlinksAccounts\"\xd0\x01\n" + "\aSetting\x12\x10\n" + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + "\x05label\x18\x02 \x01(\tR\x05label\x12 \n" + @@ -1874,7 +1976,11 @@ const file_connector_v1_connector_proto_rawDesc = "" + "\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*\xd9\x01\n" + + "\x06cursor\x18\x02 \x01(\tR\x06cursor\"$\n" + + "\x0eLinkURLRequest\x12\x12\n" + + "\x04code\x18\x01 \x01(\tR\x04code\"#\n" + + "\x0fLinkURLResponse\x12\x10\n" + + "\x03url\x18\x01 \x01(\tR\x03url*\xd9\x01\n" + "\vSettingType\x12\x1c\n" + "\x18SETTING_TYPE_UNSPECIFIED\x10\x00\x12\x17\n" + "\x13SETTING_TYPE_STRING\x10\x01\x12\x17\n" + @@ -1888,7 +1994,7 @@ const file_connector_v1_connector_proto_rawDesc = "" + "\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\xa2\x05\n" + + "\x1aREVERSIBILITY_IRREVERSIBLE\x10\x032\xea\x05\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" + @@ -1898,7 +2004,8 @@ const file_connector_v1_connector_proto_rawDesc = "" + "\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\x01\x12R\n" + - "\vTargetFacts\x12 .connector.v1.TargetFactsRequest\x1a!.connector.v1.TargetFactsResponseB\xb5\x01\n" + + "\vTargetFacts\x12 .connector.v1.TargetFactsRequest\x1a!.connector.v1.TargetFactsResponse\x12F\n" + + "\aLinkURL\x12\x1c.connector.v1.LinkURLRequest\x1a\x1d.connector.v1.LinkURLResponseB\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 ( @@ -1914,7 +2021,7 @@ func file_connector_v1_connector_proto_rawDescGZIP() []byte { } var file_connector_v1_connector_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_connector_v1_connector_proto_msgTypes = make([]protoimpl.MessageInfo, 29) +var file_connector_v1_connector_proto_msgTypes = make([]protoimpl.MessageInfo, 31) var file_connector_v1_connector_proto_goTypes = []any{ (SettingType)(0), // 0: connector.v1.SettingType (Reversibility)(0), // 1: connector.v1.Reversibility @@ -1944,14 +2051,16 @@ var file_connector_v1_connector_proto_goTypes = []any{ (*TargetFactsResponse)(nil), // 25: connector.v1.TargetFactsResponse (*ListenRequest)(nil), // 26: connector.v1.ListenRequest (*ListenResponse)(nil), // 27: connector.v1.ListenResponse - nil, // 28: connector.v1.ConfigureRequest.SettingsEntry - nil, // 29: connector.v1.ConfigureRequest.SecretsEntry - nil, // 30: connector.v1.ParseRequest.HeadersEntry - (*timestamppb.Timestamp)(nil), // 31: google.protobuf.Timestamp + (*LinkURLRequest)(nil), // 28: connector.v1.LinkURLRequest + (*LinkURLResponse)(nil), // 29: connector.v1.LinkURLResponse + nil, // 30: connector.v1.ConfigureRequest.SettingsEntry + nil, // 31: connector.v1.ConfigureRequest.SecretsEntry + nil, // 32: connector.v1.ParseRequest.HeadersEntry + (*timestamppb.Timestamp)(nil), // 33: google.protobuf.Timestamp } var file_connector_v1_connector_proto_depIdxs = []int32{ - 28, // 0: connector.v1.ConfigureRequest.settings:type_name -> connector.v1.ConfigureRequest.SettingsEntry - 29, // 1: connector.v1.ConfigureRequest.secrets:type_name -> connector.v1.ConfigureRequest.SecretsEntry + 30, // 0: connector.v1.ConfigureRequest.settings:type_name -> connector.v1.ConfigureRequest.SettingsEntry + 31, // 1: connector.v1.ConfigureRequest.secrets:type_name -> connector.v1.ConfigureRequest.SecretsEntry 7, // 2: connector.v1.DescribeResponse.events:type_name -> connector.v1.EventType 8, // 3: connector.v1.DescribeResponse.actions:type_name -> connector.v1.ActionType 10, // 4: connector.v1.DescribeResponse.lookups:type_name -> connector.v1.LookupType @@ -1961,9 +2070,9 @@ var file_connector_v1_connector_proto_depIdxs = []int32{ 11, // 8: connector.v1.ActionType.effect:type_name -> connector.v1.Effect 11, // 9: connector.v1.LookupType.effect:type_name -> connector.v1.Effect 1, // 10: connector.v1.Effect.reversibility:type_name -> connector.v1.Reversibility - 30, // 11: connector.v1.ParseRequest.headers:type_name -> connector.v1.ParseRequest.HeadersEntry + 32, // 11: connector.v1.ParseRequest.headers:type_name -> connector.v1.ParseRequest.HeadersEntry 15, // 12: connector.v1.ParseResponse.events:type_name -> connector.v1.Event - 31, // 13: connector.v1.Event.occurred_at:type_name -> google.protobuf.Timestamp + 33, // 13: connector.v1.Event.occurred_at:type_name -> google.protobuf.Timestamp 12, // 14: connector.v1.ResolveResponse.target:type_name -> connector.v1.Target 11, // 15: connector.v1.ResolveResponse.effect:type_name -> connector.v1.Effect 12, // 16: connector.v1.TargetFactsRequest.target:type_name -> connector.v1.Target @@ -1977,17 +2086,19 @@ var file_connector_v1_connector_proto_depIdxs = []int32{ 22, // 24: connector.v1.ConnectorService.Deliver:input_type -> connector.v1.DeliverRequest 26, // 25: connector.v1.ConnectorService.Listen:input_type -> connector.v1.ListenRequest 24, // 26: connector.v1.ConnectorService.TargetFacts:input_type -> connector.v1.TargetFactsRequest - 3, // 27: connector.v1.ConnectorService.Configure:output_type -> connector.v1.ConfigureResponse - 5, // 28: connector.v1.ConnectorService.Describe:output_type -> connector.v1.DescribeResponse - 14, // 29: connector.v1.ConnectorService.Parse:output_type -> connector.v1.ParseResponse - 17, // 30: connector.v1.ConnectorService.Resolve:output_type -> connector.v1.ResolveResponse - 19, // 31: connector.v1.ConnectorService.Invoke:output_type -> connector.v1.InvokeResponse - 21, // 32: connector.v1.ConnectorService.Lookup:output_type -> connector.v1.LookupResponse - 23, // 33: connector.v1.ConnectorService.Deliver:output_type -> connector.v1.DeliverResponse - 27, // 34: connector.v1.ConnectorService.Listen:output_type -> connector.v1.ListenResponse - 25, // 35: connector.v1.ConnectorService.TargetFacts:output_type -> connector.v1.TargetFactsResponse - 27, // [27:36] is the sub-list for method output_type - 18, // [18:27] is the sub-list for method input_type + 28, // 27: connector.v1.ConnectorService.LinkURL:input_type -> connector.v1.LinkURLRequest + 3, // 28: connector.v1.ConnectorService.Configure:output_type -> connector.v1.ConfigureResponse + 5, // 29: connector.v1.ConnectorService.Describe:output_type -> connector.v1.DescribeResponse + 14, // 30: connector.v1.ConnectorService.Parse:output_type -> connector.v1.ParseResponse + 17, // 31: connector.v1.ConnectorService.Resolve:output_type -> connector.v1.ResolveResponse + 19, // 32: connector.v1.ConnectorService.Invoke:output_type -> connector.v1.InvokeResponse + 21, // 33: connector.v1.ConnectorService.Lookup:output_type -> connector.v1.LookupResponse + 23, // 34: connector.v1.ConnectorService.Deliver:output_type -> connector.v1.DeliverResponse + 27, // 35: connector.v1.ConnectorService.Listen:output_type -> connector.v1.ListenResponse + 25, // 36: connector.v1.ConnectorService.TargetFacts:output_type -> connector.v1.TargetFactsResponse + 29, // 37: connector.v1.ConnectorService.LinkURL:output_type -> connector.v1.LinkURLResponse + 28, // [28:38] is the sub-list for method output_type + 18, // [18:28] is the sub-list for method input_type 18, // [18:18] is the sub-list for extension type_name 18, // [18:18] is the sub-list for extension extendee 0, // [0:18] is the sub-list for field type_name @@ -2004,7 +2115,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: 2, - NumMessages: 29, + NumMessages: 31, NumExtensions: 0, NumServices: 1, }, diff --git a/sdk/connector/v1/connector_grpc.pb.go b/sdk/connector/v1/connector_grpc.pb.go index 84a3a3e..2571c71 100644 --- a/sdk/connector/v1/connector_grpc.pb.go +++ b/sdk/connector/v1/connector_grpc.pb.go @@ -28,6 +28,7 @@ const ( ConnectorService_Deliver_FullMethodName = "/connector.v1.ConnectorService/Deliver" ConnectorService_Listen_FullMethodName = "/connector.v1.ConnectorService/Listen" ConnectorService_TargetFacts_FullMethodName = "/connector.v1.ConnectorService/TargetFacts" + ConnectorService_LinkURL_FullMethodName = "/connector.v1.ConnectorService/LinkURL" ) // ConnectorServiceClient is the client API for ConnectorService service. @@ -74,6 +75,12 @@ type ConnectorServiceClient interface { // host asks only connectors that declare target_facts, and never stores the // answer. TargetFacts(ctx context.Context, in *TargetFactsRequest, opts ...grpc.CallOption) (*TargetFactsResponse, error) + // LinkURL returns the URL a person opens to send a link code to the + // connector, such as a deep link into its bot. The host asks only + // connectors that declare links_accounts. The connector then emits an + // account.link event carrying the code and the sender's channel identity; + // the host binds that identity to the account that issued the code. + LinkURL(ctx context.Context, in *LinkURLRequest, opts ...grpc.CallOption) (*LinkURLResponse, error) } type connectorServiceClient struct { @@ -183,6 +190,16 @@ func (c *connectorServiceClient) TargetFacts(ctx context.Context, in *TargetFact return out, nil } +func (c *connectorServiceClient) LinkURL(ctx context.Context, in *LinkURLRequest, opts ...grpc.CallOption) (*LinkURLResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(LinkURLResponse) + err := c.cc.Invoke(ctx, ConnectorService_LinkURL_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // ConnectorServiceServer is the server API for ConnectorService service. // All implementations must embed UnimplementedConnectorServiceServer // for forward compatibility. @@ -227,6 +244,12 @@ type ConnectorServiceServer interface { // host asks only connectors that declare target_facts, and never stores the // answer. TargetFacts(context.Context, *TargetFactsRequest) (*TargetFactsResponse, error) + // LinkURL returns the URL a person opens to send a link code to the + // connector, such as a deep link into its bot. The host asks only + // connectors that declare links_accounts. The connector then emits an + // account.link event carrying the code and the sender's channel identity; + // the host binds that identity to the account that issued the code. + LinkURL(context.Context, *LinkURLRequest) (*LinkURLResponse, error) mustEmbedUnimplementedConnectorServiceServer() } @@ -264,6 +287,9 @@ func (UnimplementedConnectorServiceServer) Listen(*ListenRequest, grpc.ServerStr func (UnimplementedConnectorServiceServer) TargetFacts(context.Context, *TargetFactsRequest) (*TargetFactsResponse, error) { return nil, status.Error(codes.Unimplemented, "method TargetFacts not implemented") } +func (UnimplementedConnectorServiceServer) LinkURL(context.Context, *LinkURLRequest) (*LinkURLResponse, error) { + return nil, status.Error(codes.Unimplemented, "method LinkURL not implemented") +} func (UnimplementedConnectorServiceServer) mustEmbedUnimplementedConnectorServiceServer() {} func (UnimplementedConnectorServiceServer) testEmbeddedByValue() {} @@ -440,6 +466,24 @@ func _ConnectorService_TargetFacts_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } +func _ConnectorService_LinkURL_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LinkURLRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConnectorServiceServer).LinkURL(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ConnectorService_LinkURL_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConnectorServiceServer).LinkURL(ctx, req.(*LinkURLRequest)) + } + return interceptor(ctx, in, info, handler) +} + // 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) @@ -479,6 +523,10 @@ var ConnectorService_ServiceDesc = grpc.ServiceDesc{ MethodName: "TargetFacts", Handler: _ConnectorService_TargetFacts_Handler, }, + { + MethodName: "LinkURL", + Handler: _ConnectorService_LinkURL_Handler, + }, }, Streams: []grpc.StreamDesc{ {