Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

SmallBot

import { SmallBot } from "https://raw.githubusercontent.com/cybertim/SmallBotMatrix/main/mod.ts";

Wrapper to interact with the matrix.org client API

class SmallBot {
constructor(config: ISmallBotConfig);
private requestId: number;
public get ownUserId(): string | undefined;
 
private async doRequest<T>(
uri: string,
query: string[],
method?: string,
body?: string,
);
private async sendEvent(
roomId: string,
eventType: string,
content: string,
);
private async syncLoop(since?: string);
async getRoomStateName(roomId: string);
async getSync(since?: string);
async getUserProfile(userId: string);
async joinedRooms();
async sendMessage(
roomId: string,
msgType: string,
formattedBody: string,
);
async sendRoomNotice(roomId: string, msg: string);
async sendRoomText(roomId: string, msg: string);
async start();
async whoAmI();
}

§Constructors

§
new SmallBot(config: ISmallBotConfig)
[src]

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>");
       }
   }
});
@param config

§Properties

§
requestId: number
[src]
§
ownUserId: string | undefined readonly
[src]

§Methods

§
doRequest<T>(uri: string, query: string[], method?: string, body?: string) private
[src]
§
sendEvent(roomId: string, eventType: string, content: string) private
[src]
§
syncLoop(since?: string) private
[src]
§
getRoomStateName(roomId: string)
[src]

Returns MatrixRoomStateResponse of the given room id containing the current display name

@param roomId

ID of Room to get the display name

§
getSync(since?: string)
[src]

Listens for new events on /sync with a timeout based on syncTimeout This method is looped automatically when start() is called

@param since

token used to sync events from a specific point in time

§
getUserProfile(userId: string)
[src]

Returns MatrixUserProfileResponse containing the current display name of the userId

const profile = await client.getUserProfile(event.sender);
@param userId

ID of the user to retrieve the profile

§
joinedRooms()
[src]

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

§
sendMessage(roomId: string, msgType: string, formattedBody: string)
[src]

Send a custom message to a room

await client.sendMessage(roomId, "m.text", "<b>hello world</b>");
@param roomId

ID of the Room

@param msgType

type like m.text or m.notice

@param formattedBody

the HTML body of the message formatHTMLtoPlain will be used to create the plain-text version

§
sendRoomNotice(roomId: string, msg: string)
[src]

Alias of sendMessage with msgType m.notice

@param roomId

ID of the Room

@param msg

the HTML body of the message formatHTMLtoPlain will be used to create the plain-text version

§
sendRoomText(roomId: string, msg: string)
[src]

Alias of sendMessage with msgType m.text

@param roomId

ID of the Room

@param msg

the HTML body of the message formatHTMLtoPlain will be used to create the plain-text version

§
start()
[src]

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

await client.start();
§
whoAmI()
[src]

Returns the MatrixWhoAmIResponse containing the userId of the bot