import { SmallBot } from "https://deno.land/x/smallbot_matrix@0.1.2/mod.ts";
Wrapper to interact with the matrix.org client API
Constructors
new
SmallBot(config: ISmallBotConfig)Create an instance of SmallBot
const client = new SmallBot({
accessToken: "mysecretaccesstoken",
homeserverUrl: "https://matrix.org/",
eventHandler: async (client, roomId, event) => {
if (event.sender !== client.ownUserId) {
await client.sendRoomNotice(roomId, "You said: <b>" + event.content.body + "</b>");
}
}
});
Methods
private
doRequest<T>(uri: string,
query: string[],
method?: string,
body?: string,
private
sendEvent(roomId: string,
eventType: string,
content: string,
private
syncLoop(since?: string)getRoomStateName(roomId: string)
Returns MatrixRoomStateResponse
of the given room id containing the current display name
getSync(since?: string)
Listens for new events on /sync
with a timeout based on syncTimeout
This method is looped automatically when start()
is called
getUserProfile(userId: string)
Returns MatrixUserProfileResponse
containing the current display name of the userId
const profile = await client.getUserProfile(event.sender);
sendMessage()
roomId: string,
msgType: string,
formattedBody: string,
Send a custom message to a room
await client.sendMessage(roomId, "m.text", "<b>hello world</b>");
start()
Call this method to start the /sync loop and send all events into your custom handler
await client.start();