Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

feat(live): end a call on a clear Chinese hang-up request

yofizane1aab8027b956
diff --git a/server/live-call.test.ts b/server/live-call.test.ts
index 027531e2d0..e01043f2db 100644
--- a/server/live-call.test.ts
+++ b/server/live-call.test.ts
@@ -404,4 +404,26 @@ describe("spokenHangUp", () => {
it("tells the voice to delegate a hang-up request and never to end a call on its own", () => {
expect(liveInstructions({ name: "Rigel" })).toContain("- The user clearly asks you to hang up or end the call. Never end or offer to end the call on your own.");
});
+
+ it("accepts a whole Chinese request to hang up, including polite requests and farewells", () => {
+ for (const text of [
+ "挂断", "挂断。", "挂掉", "挂了", "挂了吧", "挂机", "挂吧", "挂电话", "挂断电话", "挂掉电话", "把电话挂了", "把电话挂断",
+ "结束通话", "结束这次通话", "结束本次通话", "请挂断", "请挂断电话。", "麻烦挂断", "你可以挂断了", "可以挂了", "你挂吧", "帮我挂断",
+ "就挂了吧", "好的,挂断吧", "嗯,可以挂了", "那就这样,挂断吧", "没事了,挂了吧", "谢谢,结束通话", "OK,挂断吧", "挂断吧,谢谢",
+ "结束通话,再见", "挂了,拜拜", "好的,结束通话吧,再见。", "掛斷", "掛掉", "掛了吧", "掛電話", "把電話掛了", "結束通話",
+ "請掛斷電話", "好的,掛斷吧,謝謝", "沒事了,結束通話,再見", "嗯嗯Okay那就這樣麻煩您幫我把電話掛掉了、謝謝!", "掛機", "結束這次通話",
+ ]) {
+ expect.soft(spokenHangUp(text), text).toBe(true);
+ }
+ });
+
+ it("ignores Chinese farewells, negations, questions and mentions of hanging up", () => {
+ for (const text of [
+ "再见", "拜拜", "谢谢", "好的", "就这样", "没事了", "挂", "不要挂断", "别挂", "先别挂断", "请不要结束通话", "不,挂断",
+ "怎么挂断电话?", "可以挂断吗?", "要挂断吗", "我该挂断吗", "挂断那个任务", "把电话挂在墙上", "结束通话记录的整理",
+ "查完天气就挂断", "结束它", "帮我查一下怎么结束通话", "挂断?", "掛斷?", "再見,謝謝",
+ ]) {
+ expect(spokenHangUp(text), text).toBe(false);
+ }
+ });
});
diff --git a/server/live-call.ts b/server/live-call.ts
index 824bdc76a3..f00f582834 100644
--- a/server/live-call.ts
+++ b/server/live-call.ts
@@ -214,9 +214,19 @@ const HANG_UP_LEAD = /^(?:(?:um+|uh+|er+|so|well|ok|okay|alright|all right|great
// "hang up the poster" never match, and neither does anything a page, file or bot said.
const HANG_UP = /^(?:(?:please|you can|you may|go ahead and|can you|could you|would you|will you|let's|let us)[\s,]+)*(?:hang\s+up(?:\s+(?:the|this)\s+(?:call|phone))?|end\s+(?:(?:the|this|our)\s+)?call)(?:[\s,.!]+(?:now|please|thanks|thank you|bye|goodbye))*[\s.!?]*$/i;
+// Chinese has no word boundaries, so a hang-up request must match the whole utterance.
+// 嗯 mm, 好/好的 okay, 行/可以 sure, 那 then, 就这样 that's all, 没事了 nothing else.
+// 谢谢 thanks, 再见 goodbye, 拜拜 bye.
+const ZH_HANG_UP_LEAD = /^(?:(?:嗯|ok(?:ay)?|好的?|行|可以|那|就[这這][样樣]|[没沒]事了|[谢謝]{2}|再[见見]|拜拜)[\s,,、。.!!]*)+/i;
+// 请/麻烦 please, 你/您 you, 可以 can, 帮我 help me, 就 just, 吧/了 soften or mark the end of the request.
+// 挂断/挂掉/挂了/挂机 hang up, 挂吧 go ahead and hang up, 电话 phone, 挂电话/挂断电话/挂掉电话 hang up the phone.
+// 把电话挂了/把电话挂断/把电话挂掉 hang up the phone, 结束通话 end the call, 结束这次通话/结束本次通话 end this call.
+const ZH_HANG_UP = /^(?:[请請]|麻[烦煩]|你|您|可以|[帮幫]我|就)*(?:[挂掛](?:[断斷掉了机機吧](?:[电電][话話])?|[电電][话話])|把[电電][话話][挂掛][了断斷掉]|[结結]束(?:[这這]次|本次)?通[话話])[吧了]?(?:[\s,,、。.!!]*(?:[谢謝]{2}|再[见見]|拜拜))*[\s,,、。.!!]*$/;
+
/** True only when the person's own words on a Live call are a clear request to hang up. */
export function spokenHangUp(text: string): boolean {
- return HANG_UP.test(text.trim().replace(/[\u2018\u2019]/g, "'").replace(HANG_UP_LEAD, ""));
+ return HANG_UP.test(text.trim().replace(/[\u2018\u2019]/g, "'").replace(HANG_UP_LEAD, ""))
+ || ZH_HANG_UP.test(text.trim().replace(ZH_HANG_UP_LEAD, ""));
}
export function liveInitialInput(history: LiveHistoryMessage[]) {