MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / getBotResponse

Function getBotResponse

botmzt/botmzt.ts:169–209  ·  view source on GitHub ↗

* 与机器人对话并获取图片(使用实时监听) * @param client Telegram客户端 * @param command 发送给机器人的命令 * @returns 机器人的响应消息

(client: any, command: string)

Source from the content-addressed store, hash-verified

167 // 解除对机器人的屏蔽(如果有的话)
168 try {
169 const botEntity = await client.getEntity(BOT_USERNAME);
170 await client.invoke(new Api.contacts.Unblock({
171 id: botEntity
172 }));
173 } catch (error) {
174 // 忽略解除屏蔽的错误,可能本来就没有屏蔽
175 }
176
177 // 获取机器人实体
178 const botEntity = await client.getEntity(BOT_USERNAME);
179
180 // 检查是否有对话历史,如果没有先发送 /start
181 const recentMessages = await safeGetMessages(client, botEntity, { limit: 3 });
182 const hasConversation = recentMessages.length > 0;
183
184 if (!hasConversation) {
185 await client.sendMessage(botEntity, { message: "/start" });
186 await sleep(1000);
187 }
188
189 // 开始监听机器人回复(期望图片回复)
190 const replyPromise = waitForBotReply(client, botEntity, 15000, true);
191
192 // 发送命令给机器人
193 await client.sendMessage(botEntity, {
194 message: `/${command}`
195 });
196
197 // 等待机器人响应
198 const botResponse = await replyPromise;
199
200 return botResponse;
201 } catch (error) {
202 console.error(`[mztnew] 获取机器人响应失败:`, error);
203 throw error;
204 }
205}
206
207/**
208 * 发送签到命令给机器人
209 * @param msg 原始消息
210 */
211async function sendCheckinCommand(msg: Api.Message): Promise<void> {
212 const client = await getGlobalClient();

Callers 1

sendImageWithSpoilerFunction · 0.85

Calls 3

waitForBotReplyFunction · 0.85
errorMethod · 0.80
sleepFunction · 0.50

Tested by

no test coverage detected