mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-28 02:38:44 +00:00
bots: SimpleX Calculator demo bot (#7583)
* bots: SimpleX Calculator demo bot * refactor * use local server in test * simplify * icon * simplify * expression * replies * improve * log * update name in bot address * @simplex-chat/type: 0.12.0 * simplex-chat nodejs: 7.1.0-beta.4.2 * update dependencies * option to add domain to bot address --------- Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
This commit is contained in:
co-authored by
Evgeny @ SimpleX Chat
parent
4cb244441b
commit
643a9afad6
@@ -1,12 +1,12 @@
|
||||
(async () => {
|
||||
const {bot} = await import("../dist/index.js")
|
||||
const [chat, _user, _address] = await bot.run({
|
||||
await bot.run({
|
||||
profile: {displayName: "Squaring bot example", fullName: ""},
|
||||
dbOpts: {type: "sqlite", filePrefix: "./squaring_bot"},
|
||||
options: {
|
||||
addressSettings: {welcomeMessage: "Send a number, I will square it."},
|
||||
},
|
||||
onMessage: async (ci, content) => {
|
||||
onMessage: async (ci, content, chat) => {
|
||||
const n = +content.text
|
||||
const reply = typeof n === "number" && !isNaN(n)
|
||||
? `${n} * ${n} = ${n * n}`
|
||||
|
||||
@@ -3,7 +3,7 @@ import {bot, util} from "../dist"
|
||||
|
||||
(async () => {
|
||||
const welcomeMessage = "Hello! I am a simple squaring bot.\n\nIf you send me a number, I will calculate its square."
|
||||
const [chat, _user, _address] = await bot.run({
|
||||
await bot.run({
|
||||
profile: {displayName: "Squaring bot example", fullName: ""},
|
||||
dbOpts: {type: "sqlite", filePrefix: "./squaring_bot"},
|
||||
options: {
|
||||
@@ -15,7 +15,7 @@ import {bot, util} from "../dist"
|
||||
logContacts: true,
|
||||
logNetwork: false
|
||||
},
|
||||
onMessage: async (ci, content) => {
|
||||
onMessage: async (ci, content, chat) => {
|
||||
const n = +content.text
|
||||
const reply = typeof n === "number" && !isNaN(n)
|
||||
? `${n} * ${n} = ${n * n}`
|
||||
@@ -23,11 +23,11 @@ import {bot, util} from "../dist"
|
||||
await chat.apiSendTextReply(ci, reply)
|
||||
},
|
||||
onCommands: { // command handlers can be different from commands to be shown in client UI
|
||||
"help": async (ci: T.AChatItem, _cmd: util.BotCommand) => {
|
||||
"help": async (ci: T.AChatItem, _cmd: util.BotCommand, chat) => {
|
||||
await chat.apiSendTextMessage(ci.chatInfo, welcomeMessage)
|
||||
},
|
||||
// fallback handler that will be called for all other commands
|
||||
"": async (ci: T.AChatItem, _cmd: util.BotCommand) => {
|
||||
"": async (ci: T.AChatItem, _cmd: util.BotCommand, chat) => {
|
||||
await chat.apiSendTextReply(ci, "This command is not supported")
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user