new Bridge(opts)
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object | Options to pass to the bridge
Properties
|
Methods
_customiseAppservice()
Apply any customisations required on the appService object.
addAppServicePath(opts)
Install a custom handler for an incoming HTTP API request. This allows
callers to add extra functionality, implement new APIs, etc...
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object | Named options
Properties
|
getBot() → {AppServiceBot}
Get the AS bot instance.
Returns:
- Type
- AppServiceBot
getClientFactory() → {ClientFactory}
Retrieve the matrix client factory used when sending matrix requests.
Returns:
- Type
- ClientFactory
getIntent(userIdnullable, requestopt) → {Intent}
Retrieve an Intent instance for the specified user ID. If no ID is given, an
instance for the bot itself is returned.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
userId |
string |
<nullable> |
The user ID to get an Intent for. |
request |
Request |
<optional> |
Optional. The request instance to tie the MatrixClient instance to. Useful for logging contextual request IDs. |
Returns:
The intent instance
- Type
- Intent
getIntentFromLocalpart(localpartnullable, requestopt) → {Intent}
Retrieve an Intent instance for the specified user ID localpart. This must
be the complete user localpart.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
localpart |
string |
<nullable> |
The user ID localpart to get an Intent for. |
request |
Request |
<optional> |
Optional. The request instance to tie the MatrixClient instance to. Useful for logging contextual request IDs. |
Returns:
The intent instance
- Type
- Intent
getRequestFactory() → {RequestFactory}
Retrieve the request factory used to create incoming requests.
Returns:
- Type
- RequestFactory
getRoomStore() → (nullable) {RoomBridgeStore}
Retrieve a connected room store instance.
Returns:
The connected instance ready for querying.
- Type
- RoomBridgeStore
getUserStore() → (nullable) {UserBridgeStore}
Retrieve a connected user store instance.
Returns:
The connected instance ready for querying.
- Type
- UserBridgeStore
loadDatabases() → {Promise}
Load the user and room databases. Access them via getUserStore() and getRoomStore().
Returns:
Resolved/rejected when the user/room databases have been loaded.
- Type
- Promise
provisionUser(matrixUser, provisionedUser) → {Promise}
Provision a user on the homeserver.
Parameters:
Name | Type | Description |
---|---|---|
matrixUser |
MatrixUser | The virtual user to be provisioned. |
provisionedUser |
Bridge~ProvisionedUser | Provisioning information. |
Returns:
Resolved when provisioned.
- Type
- Promise
run(port, config, appServiceInstanceopt)
Run the bridge (start listening)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
port |
Number | The port to listen on. | |
config |
Object | Configuration options | |
appServiceInstance |
AppService |
<optional> |
The AppService instance to attach to. If not provided, one will be created. |
Type Definitions
appServicePathHandler(req, res)
Handler function for custom applied HTTP API request paths. This is invoked
as defined by expressjs.
Parameters:
Name | Type | Description |
---|---|---|
req |
Request | An expressjs Request object the handler can use to inspect the incoming request. |
res |
Response | An expressjs Response object the handler can use to send the outgoing response. |
BridgeContext
Type:
- Object
Properties:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
senders |
Object | Data models on senders of this event
Properties
|
||||||||||||||||
targets |
Object | Data models on targets (e.g. state_key in
m.room.member) of this event.
Properties
|
||||||||||||||||
rooms |
Object | Data models on rooms concerning this event.
Properties
|
getLocation(protocol, fields) → {Promise.<Array.<Bridge~thirdPartyLocationResult>>}
Returned by getProtocol third-party query metadata requests
Parameters:
Name | Type | Description |
---|---|---|
protocol |
string | The name of the 3PE protocol |
fields |
Object | The location query field data as specified by the specific protocol. |
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
location_fields |
Array.<string> |
<optional> |
Names of the fields required for location lookups if location queries are supported. |
user_fields |
Array.<string> |
<optional> |
Names of the fields required for user lookups if user queries are supported. /** Invoked on requests for 3PLs |
Returns:
A Promise of a list of
3PL lookup results.
- Type
- Promise.<Array.<Bridge~thirdPartyLocationResult>>
getProtocol(protocol) → {Promise.<Bridge~thirdPartyProtocolResult>}
Invoked on requests for 3PE query metadata
Parameters:
Name | Type | Description |
---|---|---|
protocol |
string | The name of the 3PE protocol to query |
Returns:
A Promise of metadata
about 3PE queries that can be made for this protocol.
- Type
- Promise.<Bridge~thirdPartyProtocolResult>
getUser(protocol, fields) → {Promise.<Array.<Bridge~thirdPartyUserResult>>}
Invoked on requests for 3PUs
Parameters:
Name | Type | Description |
---|---|---|
protocol |
string | The name of the 3PE protocol |
fields |
Object | The user query field data as specified by the specific protocol. |
Returns:
A Promise of a list of 3PU
lookup results.
- Type
- Promise.<Array.<Bridge~thirdPartyUserResult>>
onAliasQueried(alias, roomId)
Invoked when a response is returned from onAliasQuery. Supports
both sync return values and async return values via promises.
Parameters:
Name | Type | Description |
---|---|---|
alias |
string | The alias queried. |
roomId |
string | The parsed localpart of the alias. |
onAliasQuery(alias, aliasLocalpart) → {Bridge~ProvisionedRoom|Promise.<Bridge~ProvisionedRoom, Error>}
Invoked when the bridge receives an alias query from the homeserver. Supports
both sync return values and async return values via promises.
Parameters:
Name | Type | Description |
---|---|---|
alias |
string | The alias queried. |
aliasLocalpart |
string | The parsed localpart of the alias. |
Returns:
Reject the promise / return null to not provision the room. Resolve the
promise / return a Bridge~ProvisionedRoom object to provision the room.
- Type
- Bridge~ProvisionedRoom | Promise.<Bridge~ProvisionedRoom, Error>
Example
new Bridge({
controller: {
onAliasQuery: function(alias, aliasLocalpart) {
return {
creationOpts: {
room_alias_name: aliasLocalpart, // IMPORTANT: must be set to make the link
name: aliasLocalpart,
topic: "Auto-generated bridged room"
}
};
}
}
});
onEvent(request, context)
Invoked when the bridge receives an event from the homeserver.
Parameters:
Name | Type | Description |
---|---|---|
request |
Request | The request to resolve or reject depending on the
outcome of this request. The 'data' attached to this Request is the raw event
JSON received (accessed via request.getData() ) |
context |
Bridge~BridgeContext | Context for this event, including instantiated client instances. |
onLog(line, isError)
Invoked when the bridge is attempting to log something.
Parameters:
Name | Type | Description |
---|---|---|
line |
string | The text to be logged. |
isError |
boolean | True if this line should be treated as an error msg. |
onUserQuery(matrixUser) → {Bridge~ProvisionedUser|Promise.<Bridge~ProvisionedUser, Error>}
Invoked when the bridge receives a user query from the homeserver. Supports
both sync return values and async return values via promises.
Parameters:
Name | Type | Description |
---|---|---|
matrixUser |
MatrixUser | The matrix user queried. Use getId()
to get the user ID. |
Returns:
Reject the promise / return null to not provision the user. Resolve the
promise / return a Bridge~ProvisionedUser object to provision the user.
- Type
- Bridge~ProvisionedUser | Promise.<Bridge~ProvisionedUser, Error>
Example
new Bridge({
controller: {
onUserQuery: function(matrixUser) {
var remoteUser = new RemoteUser("some_remote_id");
return {
name: matrixUser.localpart + " (Bridged)",
url: "http://someurl.com/pic.jpg",
user: remoteUser
};
}
}
});
parseLocation(alias) → {Promise.<Array.<Bridge~thirdPartyLocationResult>>}
Invoked on requests to parse 3PL aliases
Parameters:
Name | Type | Description |
---|---|---|
alias |
string | The room alias to parse. |
Returns:
A Promise of a list of
3PL lookup results.
- Type
- Promise.<Array.<Bridge~thirdPartyLocationResult>>
parseUser(userid) → {Promise.<Array.<Bridge~thirdPartyUserResult>>}
Invoked on requests to parse 3PU user IDs
Parameters:
Name | Type | Description |
---|---|---|
userid |
string | The user ID to parse. |
Returns:
A Promise of a list of 3PU
lookup results.
- Type
- Promise.<Array.<Bridge~thirdPartyUserResult>>
ProvisionedRoom
Type:
- Object
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
creationOpts |
Object | Room creation options to use when creating the room. Required. | |
remote |
RemoteRoom |
<optional> |
The remote room to link to the provisioned room. |
ProvisionedUser
Type:
- Object
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string |
<optional> |
The display name to set for the provisioned user. |
url |
string |
<optional> |
The avatar URL to set for the provisioned user. |
remote |
RemoteUser |
<optional> |
The remote user to link to the provisioned user. |
thirdPartyLocationResult
Returned by getLocation and parseLocation third-party location lookups
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
alias |
string | The Matrix room alias to the portal room representing this 3PL |
protocol |
string | The name of the 3PE protocol |
fields |
object | The normalised values of the location query field data. |
thirdPartyLookup
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
protocols |
Array.<string> | Optional list of recognised protocol names. If present, lookups for unrecognised protocols will be automatically rejected. |
getProtocol |
Bridge~getProtocol | Function. Called for requests for 3PE query metadata. |
getLocation |
Bridge~getLocation | Function. Called for requests for 3PLs. |
parseLocation |
Bridge~parseLocation | Function. Called for reverse parse requests on 3PL aliases. |
getUser |
Bridge~getUser | Function. Called for requests for 3PUs. |
parseUser |
Bridge~parseUser | Function. Called for reverse parse requests on 3PU user IDs. |
thirdPartyUserResult
Returned by getUser and parseUser third-party user lookups
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
userid |
string | The Matrix user ID for the ghost representing this 3PU |
protocol |
string | The name of the 3PE protocol |
fields |
object | The normalised values of the user query field data. |