|
|
|
@ -206,18 +206,18 @@ public class SystemFunctionHandler: NSObject { |
|
|
|
let parameters: [String: Any] = [ |
|
|
|
"type": "object", |
|
|
|
"properties": [ |
|
|
|
"phone_number": [ |
|
|
|
"contact": [ |
|
|
|
"type": "string", |
|
|
|
"description": "要拨打的电话号码" |
|
|
|
"description": "联系人姓名或电话号码" |
|
|
|
] |
|
|
|
], |
|
|
|
"required": ["phone_number"] |
|
|
|
"required": ["contact"] |
|
|
|
] |
|
|
|
|
|
|
|
let handler = MakePhoneCallHandler() |
|
|
|
_ = client.registerLocalFunction( |
|
|
|
name: "make_phone_call", |
|
|
|
description: "拨打指定电话号码", |
|
|
|
description: "拨打电话", |
|
|
|
parameters: parameters, |
|
|
|
handler: handler |
|
|
|
) |
|
|
|
@ -693,25 +693,18 @@ private class SendTextMessageHandler: NSObject, FunctionHandler, MFMessageCompos |
|
|
|
/// 拨打电话处理器 |
|
|
|
private class MakePhoneCallHandler: FunctionHandler { |
|
|
|
func handle(arguments: [String: Any]) async throws -> String { |
|
|
|
guard let phoneNumber = arguments["phone_number"] as? String else { |
|
|
|
throw ChatApiException("缺少电话号码参数") |
|
|
|
guard let contact = arguments["contact"] as? String else { |
|
|
|
throw ChatApiException("缺少联系人参数") |
|
|
|
} |
|
|
|
|
|
|
|
let result = await makePhoneCall(phoneNumber: phoneNumber) |
|
|
|
let result = await makePhoneCall(contact: contact) |
|
|
|
return "{\"result\": \"\(result.message)\"}" |
|
|
|
} |
|
|
|
|
|
|
|
private func makePhoneCall(phoneNumber: String) async -> Result { |
|
|
|
// 清理电话号码,移除空格和特殊字符 |
|
|
|
let cleanedNumber = phoneNumber.replacingOccurrences(of: " ", with: "") |
|
|
|
.replacingOccurrences(of: "-", with: "") |
|
|
|
.replacingOccurrences(of: "(", with: "") |
|
|
|
.replacingOccurrences(of: ")", with: "") |
|
|
|
|
|
|
|
guard let url = URL(string: "tel:\(cleanedNumber)") else { |
|
|
|
private func makePhoneCall(contact: String) async -> Result { |
|
|
|
guard let url = URL(string: "tel:\(contact)") else { |
|
|
|
return Result(success: false, message: "无法创建电话URL") |
|
|
|
} |
|
|
|
|
|
|
|
return await withCheckedContinuation { continuation in |
|
|
|
DispatchQueue.main.async { |
|
|
|
if UIApplication.shared.canOpenURL(url) { |
|
|
|
|