MatrixTikTok/index.js

26 lines
796 B
JavaScript
Raw Normal View History

2023-02-22 15:34:50 -05:00
const sdk = require("matrix-bot-sdk");
const MatrixClient = sdk.MatrixClient;
const SimpleFsStorageProvider = sdk.SimpleFsStorageProvider;
const AutojoinRoomsMixin = sdk.AutojoinRoomsMixin;
const homeserverUrl = "";
const accessToken = "";
const storage = new SimpleFsStorageProvider("config/bot.json");
const client = new MatrixClient(homeserverUrl, accessToken, storage);
AutojoinRoomsMixin.setupOnClient(client);
client.start().then(() => console.log("Client started!"));
client.on("room.message", (roomId, event) => {
if (! event["content"]) return;
const sender = event["sender"];
const body = event["content"]["body"];
console.log(`${roomId}: ${sender} says '${body}`);
});
client.sendMessage(roomId, {
"msgtype": "m.text",
"body": "This is message text.",
});