|
|
|
@ -60,6 +60,18 @@ class SystemFunctionHandler(private val context: Context? = null) { |
|
|
|
// handler = TranslationModeHandler(context) |
|
|
|
// ) |
|
|
|
|
|
|
|
// 注册获取联系人列表函数 |
|
|
|
client.registerLocalFunction( |
|
|
|
name = "get_contacts_list", |
|
|
|
description = "获取用户通信录联系人列表", |
|
|
|
parameters = mapOf( |
|
|
|
"type" to "object", |
|
|
|
"properties" to emptyMap<String, Any>(), |
|
|
|
"required" to emptyList<String>() |
|
|
|
), |
|
|
|
handler = GetContactsListHandler(context) |
|
|
|
) |
|
|
|
|
|
|
|
// 注册发送短信函数 |
|
|
|
client.registerLocalFunction( |
|
|
|
name = "send_text_message", |
|
|
|
@ -67,7 +79,7 @@ class SystemFunctionHandler(private val context: Context? = null) { |
|
|
|
parameters = mapOf( |
|
|
|
"type" to "object", |
|
|
|
"properties" to mapOf( |
|
|
|
"contact" to mapOf( |
|
|
|
"phone_number" to mapOf( |
|
|
|
"type" to "string", |
|
|
|
"description" to "电话号码" |
|
|
|
), |
|
|
|
@ -76,23 +88,11 @@ class SystemFunctionHandler(private val context: Context? = null) { |
|
|
|
"description" to "短信内容" |
|
|
|
) |
|
|
|
), |
|
|
|
"required" to listOf("contact", "message") |
|
|
|
"required" to listOf("phone_number", "message") |
|
|
|
), |
|
|
|
handler = SendTextMessageHandler(context) |
|
|
|
) |
|
|
|
|
|
|
|
// 注册获取联系人列表函数 |
|
|
|
client.registerLocalFunction( |
|
|
|
name = "get_contacts_list", |
|
|
|
description = "获取用户通信录联系人列表", |
|
|
|
parameters = mapOf( |
|
|
|
"type" to "object", |
|
|
|
"properties" to emptyMap<String, Any>(), |
|
|
|
"required" to emptyList<String>() |
|
|
|
), |
|
|
|
handler = GetContactsListHandler(context) |
|
|
|
) |
|
|
|
|
|
|
|
// 注册拨打电话函数 |
|
|
|
client.registerLocalFunction( |
|
|
|
name = "make_phone_call", |
|
|
|
@ -100,12 +100,12 @@ class SystemFunctionHandler(private val context: Context? = null) { |
|
|
|
parameters = mapOf( |
|
|
|
"type" to "object", |
|
|
|
"properties" to mapOf( |
|
|
|
"contact" to mapOf( |
|
|
|
"phone_number" to mapOf( |
|
|
|
"type" to "string", |
|
|
|
"description" to "联系人姓名或电话号码" |
|
|
|
"description" to "联系人电话号码" |
|
|
|
) |
|
|
|
), |
|
|
|
"required" to listOf("contact") |
|
|
|
"required" to listOf("phone_number") |
|
|
|
), |
|
|
|
handler = MakePhoneCallHandler(context) |
|
|
|
) |
|
|
|
@ -495,10 +495,10 @@ private class TranslationModeHandler(private val context: Context?) : FunctionHa |
|
|
|
*/ |
|
|
|
private class SendTextMessageHandler(private val context: Context?) : FunctionHandler { |
|
|
|
override suspend fun handle(arguments: Map<String, Any>): String { |
|
|
|
val contact = arguments["contact"] as? String |
|
|
|
val phone_number = arguments["phone_number"] as? String |
|
|
|
val message = arguments["message"] as? String |
|
|
|
|
|
|
|
if (contact == null || message == null) { |
|
|
|
if (phone_number == null || message == null) { |
|
|
|
return JSONObject().apply { |
|
|
|
put("error", JSONObject().apply { |
|
|
|
put("code", "invalid_arguments") |
|
|
|
@ -529,12 +529,12 @@ private class SendTextMessageHandler(private val context: Context?) : FunctionHa |
|
|
|
}.toString() |
|
|
|
} |
|
|
|
|
|
|
|
val phoneNumber = handler.getPhoneNumberForContact(contact) |
|
|
|
val phoneNumber = handler.getPhoneNumberForContact(phone_number) |
|
|
|
if (phoneNumber.isEmpty()) { |
|
|
|
return JSONObject().apply { |
|
|
|
put("error", JSONObject().apply { |
|
|
|
put("code", "contact_not_found") |
|
|
|
put("message", "未找到联系人信息: $contact") |
|
|
|
put("message", "未找到联系人信息: $phone_number") |
|
|
|
}) |
|
|
|
}.toString() |
|
|
|
} |
|
|
|
@ -556,7 +556,7 @@ private class SendTextMessageHandler(private val context: Context?) : FunctionHa |
|
|
|
} |
|
|
|
|
|
|
|
JSONObject().apply { |
|
|
|
put("result", "已成功向${contact}发送短信") |
|
|
|
put("result", "已成功向${phone_number}发送短信") |
|
|
|
put("phone", phoneNumber) |
|
|
|
put("message", message) |
|
|
|
}.toString() |
|
|
|
@ -637,13 +637,13 @@ private class MakePhoneCallHandler(private val context: Context?) : FunctionHand |
|
|
|
} |
|
|
|
|
|
|
|
override suspend fun handle(arguments: Map<String, Any>): String { |
|
|
|
val contact = arguments["contact"] as? String |
|
|
|
val phone_number = arguments["phone_number"] as? String |
|
|
|
|
|
|
|
if (contact == null) { |
|
|
|
if (phone_number == null) { |
|
|
|
return JSONObject().apply { |
|
|
|
put("error", JSONObject().apply { |
|
|
|
put("code", "invalid_arguments") |
|
|
|
put("message", "缺少必要参数:contact") |
|
|
|
put("message", "缺少必要参数:phone_number") |
|
|
|
}) |
|
|
|
}.toString() |
|
|
|
} |
|
|
|
@ -670,12 +670,12 @@ private class MakePhoneCallHandler(private val context: Context?) : FunctionHand |
|
|
|
}.toString() |
|
|
|
} |
|
|
|
|
|
|
|
val phoneNumber = handler.getPhoneNumberForContact(contact) |
|
|
|
val phoneNumber = handler.getPhoneNumberForContact(phone_number) |
|
|
|
if (phoneNumber.isEmpty()) { |
|
|
|
return JSONObject().apply { |
|
|
|
put("error", JSONObject().apply { |
|
|
|
put("code", "contact_not_found") |
|
|
|
put("message", "未找到联系人信息: $contact") |
|
|
|
put("message", "未找到联系人信息: $phone_number") |
|
|
|
}) |
|
|
|
}.toString() |
|
|
|
} |
|
|
|
@ -688,7 +688,7 @@ private class MakePhoneCallHandler(private val context: Context?) : FunctionHand |
|
|
|
context.startActivity(intent) |
|
|
|
|
|
|
|
JSONObject().apply { |
|
|
|
put("result", "正在拨打${contact}的电话") |
|
|
|
put("result", "正在拨打${phone_number}的电话") |
|
|
|
put("phone", phoneNumber) |
|
|
|
}.toString() |
|
|
|
} catch (e: SecurityException) { |
|
|
|
@ -1106,10 +1106,11 @@ private class GetCurrentLocationHandler(private val context: Context?) : Functio |
|
|
|
|
|
|
|
val result = JSONObject().apply { |
|
|
|
put("result", JSONObject().apply { |
|
|
|
put("longitude", longitude) |
|
|
|
put("latitude", latitude) |
|
|
|
put("timestamp", System.currentTimeMillis()) |
|
|
|
|
|
|
|
put("经度", longitude) // 经度 |
|
|
|
put("纬度", latitude) // 纬度 |
|
|
|
put("经纬度", "$latitude,$longitude") |
|
|
|
put("纬经度", "$longitude,$latitude") |
|
|
|
put("时间戳", System.currentTimeMillis()) |
|
|
|
}) |
|
|
|
}.toString() |
|
|
|
|
|
|
|
|