-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.ts
50 lines (42 loc) · 1.23 KB
/
example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Chats } from "./chats.ts";
import { Bot, Context } from "https://deno.land/x/[email protected]/mod.ts";
/// Setup Bot
type MyContext = Context; // Can be extended.
const bot = new Bot<MyContext>("token");
bot.command("start", async (ctx) => {
/* const sent = */ await ctx.reply("Hello.");
// console.log(sent); // Dynamically generated!
});
/// Test setup
const chats = new Chats(bot);
const user = chats.newUser({
id: 123,
blocked: false,
username: "mak",
first_name: "kek",
last_name: "none",
language_code: "en",
});
const group = chats.newGroup({
id: 234,
title: "Movie Night",
owner: {
status: "creator",
user: { id: 345, first_name: "The Owner", is_bot: false },
is_anonymous: false,
},
});
user.join(group.chat_id);
user.onEvent("message", () => {
// console.log("User recieved a message from the bot saying", m.text);
});
// Send a message to the bot.
// await user.sendMessage("Hello");
await user.command("start");
// Send a message to the group.
await user.in(group).sendMessage("Hi everyone!");
// or first declare a state of the user:
const userInGroup = user.in(group);
await userInGroup.sendMessage("Hi again!");
// and other properties can be accesses as well:
// userInGroup.sendVideo(...)