diff --git a/internal/contracts/connector/v1/connector.pb.go b/internal/contracts/connector/v1/connector.pb.go
index 3fed2e2a4..35ad7e24b 100644
--- a/internal/contracts/connector/v1/connector.pb.go
+++ b/internal/contracts/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\xc4\x01\n" +
+ "\vTargetFacts\x12 .connector.v1.TargetFactsRequest\x1a!.connector.v1.TargetFactsResponse\x12F\n" +
+ "\aLinkURL\x12\x1c.connector.v1.LinkURLRequest\x1a\x1d.connector.v1.LinkURLResponseB\xc4\x01\n" +
"\x10com.connector.v1B\x0eConnectorProtoP\x01ZOgithub.com/samcharles93/archie-core/internal/contracts/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/internal/contracts/connector/v1/connector_grpc.pb.go b/internal/contracts/connector/v1/connector_grpc.pb.go
index 84a3a3e55..2571c715d 100644
--- a/internal/contracts/connector/v1/connector_grpc.pb.go
+++ b/internal/contracts/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{
{
diff --git a/modules/connectors/capabilities.go b/modules/connectors/capabilities.go
index bbcc2b6ba..45ebad657 100644
--- a/modules/connectors/capabilities.go
+++ b/modules/connectors/capabilities.go
@@ -84,6 +84,9 @@ type Capabilities struct {
Listens bool `json:"listens"`
// TargetFacts says the connector answers target fact requests.
TargetFacts bool `json:"target_facts"`
+ // LinksAccounts says the connector can link a person's channel identity
+ // to their account.
+ LinksAccounts bool `json:"links_accounts"`
}
// Event returns the named event type.
@@ -109,12 +112,13 @@ func find(list []Capability, name string) (Capability, bool) {
// capabilitiesOf lists what a connector described, each kind in name order.
func capabilitiesOf(desc *pb.DescribeResponse) Capabilities {
caps := Capabilities{
- Events: make([]Capability, 0, len(desc.GetEvents())),
- Actions: make([]Capability, 0, len(desc.GetActions())),
- Deliveries: make([]Capability, 0, len(desc.GetDeliveries())),
- Lookups: make([]Capability, 0, len(desc.GetLookups())),
- Listens: desc.GetListens(),
- TargetFacts: desc.GetTargetFacts(),
+ Events: make([]Capability, 0, len(desc.GetEvents())),
+ Actions: make([]Capability, 0, len(desc.GetActions())),
+ Deliveries: make([]Capability, 0, len(desc.GetDeliveries())),
+ Lookups: make([]Capability, 0, len(desc.GetLookups())),
+ Listens: desc.GetListens(),
+ TargetFacts: desc.GetTargetFacts(),
+ LinksAccounts: desc.GetLinksAccounts(),
}
for _, e := range desc.GetEvents() {
caps.Events = append(caps.Events, Capability{Name: e.GetName(), Description: e.GetDescription(), Schema: schemaOrEmpty(e.GetSchema())})
diff --git a/modules/connectors/connector.go b/modules/connectors/connector.go
index 366bde4bc..0dfd4da32 100644
--- a/modules/connectors/connector.go
+++ b/modules/connectors/connector.go
@@ -178,6 +178,8 @@ type Connector struct {
listens bool
// facts says it answers TargetFacts.
facts bool
+ // links says it serves LinkURL.
+ links bool
// settings is the schema it declared for its operator settings.
settings []Setting
// caps is everything it declared, in the form that is stored.
@@ -204,6 +206,7 @@ func open(ctx context.Context, name string, client pb.ConnectorServiceClient, se
deliveries: map[string]*jsonschema.Resolved{},
listens: desc.GetListens(),
facts: desc.GetTargetFacts(),
+ links: desc.GetLinksAccounts(),
settings: connectorSettings(desc.GetSettings()),
caps: capabilitiesOf(desc),
}
@@ -348,6 +351,26 @@ func (c *Connector) TargetFacts(ctx context.Context, t Target) (TargetFacts, err
}, nil
}
+// LinksAccounts reports whether the connector can link a person's channel
+// identity to their account.
+func (c *Connector) LinksAccounts() bool { return c.links }
+
+// LinkURL asks the connector for the URL that delivers a link code to it.
+func (c *Connector) LinkURL(ctx context.Context, code string) (string, error) {
+ if !c.links {
+ return "", fmt.Errorf("connector %q: %w", c.name, ErrUnknownName)
+ }
+ req := &pb.LinkURLRequest{Code: code}
+ resp, err := c.client.LinkURL(ctx, req)
+ if err != nil {
+ return "", fmt.Errorf("connector %q: link URL: %w", c.name, err)
+ }
+ if resp.GetUrl() == "" {
+ return "", fmt.Errorf("connector %q: link URL: the connector returned none", c.name)
+ }
+ return resp.GetUrl(), nil
+}
+
// Declarations lists the connector's lookups and actions in name order.
func (c *Connector) Declarations() []Declaration {
out := make([]Declaration, 0, len(c.lookups)+len(c.actions))
diff --git a/modules/connectors/module.go b/modules/connectors/module.go
index 8f5ccc57f..20d12f7d3 100644
--- a/modules/connectors/module.go
+++ b/modules/connectors/module.go
@@ -203,6 +203,29 @@ func (m *Module) Delivering(delivery string) []*Connector {
return out
}
+// LinkableChannels lists the running connectors that can link a person's
+// channel identity to their account, in name order.
+func (m *Module) LinkableChannels(context.Context) ([]string, error) {
+ m.mu.RLock()
+ defer m.mu.RUnlock()
+ var out []string
+ for _, name := range slices.Sorted(maps.Keys(m.running)) {
+ if m.running[name].LinksAccounts() {
+ out = append(out, name)
+ }
+ }
+ return out, nil
+}
+
+// LinkURL asks the running connector for the URL that delivers a link code.
+func (m *Module) LinkURL(ctx context.Context, connector, code string) (string, error) {
+ c, ok := m.Get(connector)
+ if !ok {
+ return "", fmt.Errorf("connector %q isn't running", connector)
+ }
+ return c.LinkURL(ctx, code)
+}
+
// Declarations lists every running connector's lookups and actions and every
// MCP server's declared tools, ordered by name and then by tool name.
func (m *Module) Declarations() []Declaration {
diff --git a/modules/governance/internal/store/people.go b/modules/governance/internal/store/people.go
deleted file mode 100644
index bc15ab93c..000000000
--- a/modules/governance/internal/store/people.go
+++ /dev/null
@@ -1,104 +0,0 @@
-package store
-
-import (
- "context"
- "database/sql"
- "errors"
- "fmt"
-
- "github.com/google/uuid"
-)
-
-// Person is one person of the organisation with the identities that are
-// theirs.
-type Person struct {
- ID uuid.UUID `db:"id"`
- Name string `db:"name"`
- Authority bool `db:"authority"`
- Identities []string `db:"-"`
-}
-
-// People returns the organisation's people by name, each with their identities.
-func (s *Store) People(ctx context.Context, orgID string) ([]Person, error) {
- var people []Person
- if err := s.db.SelectContext(ctx, &people, `
- SELECT id, name, authority FROM governance.people WHERE org_id = $1 ORDER BY name`, orgID); err != nil {
- return nil, fmt.Errorf("list people: %w", err)
- }
- var ids []struct {
- PersonID uuid.UUID `db:"person_id"`
- Identity string `db:"identity"`
- }
- if err := s.db.SelectContext(ctx, &ids, `
- SELECT person_id, identity FROM governance.person_identities WHERE org_id = $1 ORDER BY identity`, orgID); err != nil {
- return nil, fmt.Errorf("list identities: %w", err)
- }
- byID := make(map[uuid.UUID]int, len(people))
- for i := range people {
- people[i].Identities = []string{}
- byID[people[i].ID] = i
- }
- for _, id := range ids {
- if i, ok := byID[id.PersonID]; ok {
- people[i].Identities = append(people[i].Identities, id.Identity)
- }
- }
- return people, nil
-}
-
-// PersonByIdentity returns the person who holds identity; ok is false when no
-// one does.
-func (s *Store) PersonByIdentity(ctx context.Context, orgID, identity string) (Person, bool, error) {
- var p Person
- err := s.db.GetContext(ctx, &p, `
- SELECT p.id, p.name, p.authority FROM governance.people p
- JOIN governance.person_identities i ON i.person_id = p.id AND i.org_id = p.org_id
- WHERE i.org_id = $1 AND i.identity = $2`, orgID, identity)
- if errors.Is(err, sql.ErrNoRows) {
- return Person{}, false, nil
- }
- if err != nil {
- return Person{}, false, fmt.Errorf("read person by identity: %w", err)
- }
- return p, true, nil
-}
-
-// ReplacePeople makes people the organisation's whole set: it adds or updates
-// each one, and removes anyone not listed.
-func (s *Store) ReplacePeople(ctx context.Context, orgID string, people []Person) error {
- tx, err := s.db.BeginTxx(ctx, nil)
- if err != nil {
- return fmt.Errorf("begin replace people: %w", err)
- }
- defer func() { _ = tx.Rollback() }()
- keep := make([]uuid.UUID, 0, len(people))
- for _, p := range people {
- keep = append(keep, p.ID)
- }
- if _, err := tx.ExecContext(ctx, `
- DELETE FROM governance.people WHERE org_id = $1 AND NOT (id = ANY($2))`, orgID, keep); err != nil {
- return fmt.Errorf("remove people: %w", err)
- }
- if _, err := tx.ExecContext(ctx, `DELETE FROM governance.person_identities WHERE org_id = $1`, orgID); err != nil {
- return fmt.Errorf("clear identities: %w", err)
- }
- for _, p := range people {
- if _, err := tx.ExecContext(ctx, `
- INSERT INTO governance.people (id, org_id, name, authority) VALUES ($1, $2, $3, $4)
- ON CONFLICT (id) DO UPDATE SET name = EXCLUDED.name, authority = EXCLUDED.authority`,
- p.ID, orgID, p.Name, p.Authority); err != nil {
- return fmt.Errorf("save person %q: %w", p.Name, err)
- }
- for _, identity := range p.Identities {
- if _, err := tx.ExecContext(ctx, `
- INSERT INTO governance.person_identities (org_id, identity, person_id) VALUES ($1, $2, $3)`,
- orgID, identity, p.ID); err != nil {
- return fmt.Errorf("save identity %q: %w", identity, err)
- }
- }
- }
- if err := tx.Commit(); err != nil {
- return fmt.Errorf("commit people: %w", err)
- }
- return nil
-}
diff --git a/modules/governance/people.go b/modules/governance/people.go
deleted file mode 100644
index 1afba4b09..000000000
--- a/modules/governance/people.go
+++ /dev/null
@@ -1,162 +0,0 @@
-package governance
-
-import (
- "context"
- "errors"
- "fmt"
- "net/http"
- "slices"
- "strings"
-
- "github.com/danielgtaylor/huma/v2"
- "github.com/google/uuid"
-
- "github.com/samcharles93/archie-core/internal/platform/httpapi"
- "github.com/samcharles93/archie-core/modules/governance/internal/store"
-)
-
-// Verified is a person an identity was verified as.
-type Verified struct {
- // ID is the person's id, as the settings name them.
- ID string
- Name string
- // Authority is whether the person may approve changes to policy and
- // ceilings, such as raising an action class.
- Authority bool
- // Approver is whether the person may answer an approval for an action:
- // they hold authority, are the default owner, or are on the escalation
- // path. A person a request was put to as the target's owner may answer
- // it without.
- Approver bool
-}
-
-// Verify returns the person who holds identity, such as "telegram:1001"; ok is
-// false when no person does, so the identity is not verified.
-func (m *Module) Verify(ctx context.Context, identity string) (Verified, bool, error) {
- p, ok, err := m.store.PersonByIdentity(ctx, m.orgID, identity)
- if err != nil || !ok {
- return Verified{}, false, err
- }
- set, err := m.Settings(ctx)
- if err != nil {
- return Verified{}, false, err
- }
- id := p.ID.String()
- onPath := slices.ContainsFunc(set.Escalation, func(st Step) bool { return st.Person == id })
- approver := p.Authority || set.DefaultOwner == id || onPath
- return Verified{ID: id, Name: p.Name, Authority: p.Authority, Approver: approver}, true, nil
-}
-
-// PersonID returns the id of the person who holds identity; ok is false when
-// nobody does.
-func (m *Module) PersonID(ctx context.Context, identity string) (string, bool, error) {
- p, ok, err := m.store.PersonByIdentity(ctx, m.orgID, identity)
- if err != nil || !ok {
- return "", false, err
- }
- return p.ID.String(), true, nil
-}
-
-// personRequest is a person as the API shows and sets them. An empty id is a
-// new person.
-type personRequest struct {
- ID string `json:"id" required:"false" doc:"Empty for a new person"`
- Name string `json:"name"`
- Authority bool `json:"authority"`
- Identities []string `json:"identities"`
-}
-
-func (m *Module) getPeople(ctx context.Context, _ *struct{}) (*httpapi.Reply[[]personRequest], error) {
- people, err := m.store.People(ctx, m.orgID)
- if err != nil {
- m.log.ErrorContext(ctx, "read people", "error", err)
- return nil, huma.NewError(http.StatusInternalServerError, "couldn't read the people")
- }
- out := make([]personRequest, 0, len(people))
- for _, p := range people {
- out = append(out, personRequest{ID: p.ID.String(), Name: p.Name, Authority: p.Authority, Identities: p.Identities})
- }
- return httpapi.OK(out), nil
-}
-
-// putPeople replaces the organisation's people with the list in the request.
-func (m *Module) putPeople(ctx context.Context, in *struct{ Body []personRequest }) (*httpapi.Reply[[]personRequest], error) {
- req := in.Body
- people, err := peopleOf(req)
- if err != nil {
- return nil, huma.NewError(http.StatusBadRequest, err.Error())
- }
- set, err := m.Settings(ctx)
- if err != nil {
- m.log.ErrorContext(ctx, "read settings", "error", err)
- return nil, huma.NewError(http.StatusInternalServerError, "couldn't save the people")
- }
- if err := set.stillKnows(people); err != nil {
- return nil, huma.NewError(http.StatusConflict, err.Error())
- }
- if err := m.store.ReplacePeople(ctx, m.orgID, people); err != nil {
- m.log.ErrorContext(ctx, "put people", "error", err)
- return nil, huma.NewError(http.StatusInternalServerError, "couldn't save the people")
- }
- return m.getPeople(ctx, nil)
-}
-
-// stillKnows refuses to remove a person the settings name.
-func (s Settings) stillKnows(people []store.Person) error {
- if err := s.knows(people); err != nil {
- return errors.New("a person the settings name can't be removed; change the settings first")
- }
- return nil
-}
-
-// peopleOf validates a request and returns the people it describes. A name is
-// kept once, and an identity belongs to one person.
-func peopleOf(req []personRequest) ([]store.Person, error) {
- people := make([]store.Person, 0, len(req))
- names := map[string]bool{}
- held := map[string]bool{}
- for _, pr := range req {
- name := strings.TrimSpace(pr.Name)
- if name == "" {
- return nil, errors.New("every person needs a name")
- }
- key := strings.ToLower(name)
- if names[key] {
- return nil, fmt.Errorf("%q is listed twice", name)
- }
- names[key] = true
- id := uuid.New()
- if pr.ID != "" {
- parsed, err := uuid.Parse(pr.ID)
- if err != nil {
- return nil, fmt.Errorf("%q has an id that isn't valid", name)
- }
- id = parsed
- }
- idents := make([]string, 0, len(pr.Identities))
- for _, raw := range pr.Identities {
- identity, err := ParseIdentity(raw)
- if err != nil {
- return nil, err
- }
- if held[identity] {
- return nil, fmt.Errorf("%q belongs to one person only", identity)
- }
- held[identity] = true
- idents = append(idents, identity)
- }
- people = append(people, store.Person{ID: id, Name: name, Authority: pr.Authority, Identities: idents})
- }
- return people, nil
-}
-
-// ParseIdentity returns raw as an identity: a channel and an account on it,
-// such as "telegram:1001".
-func ParseIdentity(raw string) (string, error) {
- identity := strings.TrimSpace(raw)
- channel, account, ok := strings.Cut(identity, ":")
- if !ok || channel == "" || account == "" || strings.ContainsAny(identity, " \t\n") {
- return "", fmt.Errorf("%q isn't an identity; write the channel and the account, such as telegram:1001", raw)
- }
- return identity, nil
-}
diff --git a/proto/connector/v1/connector.proto b/proto/connector/v1/connector.proto
index f9dbc3dbd..e0b980a90 100644
--- a/proto/connector/v1/connector.proto
+++ b/proto/connector/v1/connector.proto
@@ -44,6 +44,12 @@ service ConnectorService {
// host asks only connectors that declare target_facts, and never stores the
// answer.
rpc TargetFacts(TargetFactsRequest) returns (TargetFactsResponse);
+ // 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.
+ rpc LinkURL(LinkURLRequest) returns (LinkURLResponse);
}
message ConfigureRequest {
@@ -69,6 +75,9 @@ message DescribeResponse {
repeated Setting settings = 8;
// version is the connector's own release.
string version = 9;
+ // links_accounts says the connector serves LinkURL and emits account.link
+ // events, so a person can link their channel identity to an account.
+ bool links_accounts = 10;
}
// Setting is one value an operator enters for an extension to run.
@@ -256,3 +265,12 @@ message ListenResponse {
repeated Event events = 1;
string cursor = 2;
}
+
+message LinkURLRequest {
+ // code is the single-use link code the person sends to the connector.
+ string code = 1;
+}
+message LinkURLResponse {
+ // url opens the connector's channel with the code attached.
+ string url = 1;
+}
diff --git a/ui/src/org/OrgPeoplePage.vue b/ui/src/org/OrgPeoplePage.vue
deleted file mode 100644
index e81fe2569..000000000
--- a/ui/src/org/OrgPeoplePage.vue
+++ /dev/null
@@ -1,182 +0,0 @@
-
-
-
-
-
-
-
{{ error }}
-
-
-
-
-
-
-
- Name
- Authority
- Identities
- Actions
-
-
-
-
-
-
-
-
- change(person, { authority: on })"
- />
-
-
-
-
- {{ label(value) }}
-
-
-
-
-
-
-
-
-
-
-
- Remove
-
-
-
-
- Loading peopleā¦
-
-
-
- No people yet
-
-
-
-
-
-
-