Files
kefu_cloud/server/internal/handler/contact_extract_test.go
T
yml2213 6070cf47dc 支持访客实时输入草稿展示与联系方式自动识别
坐席输入框上方显示「对方正在输入」草稿;从草稿/消息提取手机微信邮箱QQ并追加入库,不覆盖已有联系方式。
2026-07-19 00:19:24 +08:00

29 lines
717 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package handler
import "testing"
func TestExtractContactsFromText(t *testing.T) {
text := "你好,我微信是 abc_wx_01,手机 13800138000,邮箱 test@example.com QQ123456"
got := extractContactsFromText(text)
kinds := map[string]string{}
for _, c := range got {
kinds[c.Kind] = c.Value
}
if kinds["phone"] != "13800138000" {
t.Fatalf("phone: %+v", got)
}
if kinds["wechat"] != "abc_wx_01" {
t.Fatalf("wechat: %+v", got)
}
if kinds["email"] != "test@example.com" {
t.Fatalf("email: %+v", got)
}
if kinds["qq"] != "123456" {
t.Fatalf("qq: %+v", got)
}
// 不完整不应误提
if len(extractContactsFromText("微信 ab")) != 0 {
t.Fatal("partial wechat should not extract")
}
}