https://www.txthinking.com/zhi.html
bun add github:txthinkinginc/zhi.js
You only need to make AvatarUUID once for each Chat
import zhi from 'zhi';
var BotToken = "" // get from bot page https://www.txthinking.com/zhi.html
var ChatUUID = "" // get from bot page https://www.txthinking.com/zhi.html
var Key = "" // your Chat Key
var UserUUID = "" // get from bot page https://www.txthinking.com/zhi.html
var avatar = "" // local avatar image path
var b = await Bun.file(avatar).bytes()
var AvatarUUID = await zhi.avatar(BotToken, ChatUUID, Key, UserUUID, b)
console.log(AvatarUUID)
import zhi from 'zhi';
var bot = await zhi.Bot.init("Bot Token", [ // get from bot page https://www.txthinking.com/zhi.html, one Bot Token can be used in multiple Chats
{
ChatUUID: "", // get from bot page https://www.txthinking.com/zhi.html
Key: "", // your Chat Key
UserUUID: "", // get from bot page https://www.txthinking.com/zhi.html
Name: "", // bot name you want
AvatarUUID:"", // AvatarUUID you maked
},
])
await bot.connect()
bot.on_message(async function(m) {
console.log(m)
await bot.send_text(m.ChatUUID, "Yes!")
})
A common scenario is sending infrequent but important notifications.
import zhi from 'zhi';
async function notify(str){
var bot = await zhi.Bot.init("Bot Token", [
{
ChatUUID: "",
Key: "",
UserUUID: "",
Name: "",
AvatarUUID:"",
},
])
await bot.connect()
await bot.send_text("The ChatUUID", str)
bot.close()
}
await notify("something went wrong")
import zhi from 'zhi';
var bot = await zhi.Bot.init("Bot Token", [
{
ChatUUID: "",
Key: "",
UserUUID: "",
Name: "",
AvatarUUID:"",
},
])
await bot.connect()
// Reconnect
bot.on_close(async function(e) {
console.log("close", e)
bot.close()
await Bun.sleep(60*1000); // 60s or less
await bot.connect()
})
bot.on_message(async function(m) {
console.log(m)
await bot.send_text(m.ChatUUID, "Yes!")
})
// send a message at where you want
await bot.send_text("The ChatUUID", "Yes!")