Module

x/smallbot_matrix/mod.ts>SmallBot

Small Matrix Little Bot for Deno
Latest
class SmallBot
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>");
       }
   }
});

Properties

private
requestId: number
readonly
ownUserId: string | undefined

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);

Returns the MatrixJoinedRoomsResponse containing a Map of all joined roomId's

sendMessage(
roomId: string,
msgType: string,
formattedBody: string,
)

Send a custom message to a room

await client.sendMessage(roomId, "m.text", "<b>hello world</b>");
sendRoomNotice(roomId: string, msg: string)

Alias of sendMessage with msgType m.notice

sendRoomText(roomId: string, msg: string)

Alias of sendMessage with msgType m.text

Call this method to start the /sync loop and send all events into your custom handler

await client.start();

Returns the MatrixWhoAmIResponse containing the userId of the bot

import SmallBot
import { SmallBot } from "https://deno.land/x/smallbot_matrix@0.1.2/mod.ts";