new Bridge(opts)
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object | Options to pass to the bridge
Properties
|
Methods
getBot() → {AppServiceBot}
Get the AS bot instance.
Returns:
- Type
- AppServiceBot
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
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
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
|
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
};
}
}
});
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. |