mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-02 17:07:41 +08:00
优化:飞书发送通道的消息卡片允许自定义标题模板
This commit is contained in:
parent
8d90548049
commit
c88b057232
@ -1637,12 +1637,28 @@ public class SenderActivity extends AppCompatActivity {
|
||||
final EditText editTextFeishuWebhook = view1.findViewById(R.id.editTextFeishuWebhook);
|
||||
final ClearEditText editTextFeishuSecret = view1.findViewById(R.id.editTextFeishuSecret);
|
||||
final RadioGroup radioGroupFeishuMsgType = view1.findViewById(R.id.radioGroupFeishuMsgType);
|
||||
final EditText editTextFeishuTitle = view1.findViewById(R.id.editTextFeishuTitle);
|
||||
final LinearLayout layoutTitleTemplate = view1.findViewById(R.id.layoutTitleTemplate);
|
||||
|
||||
if (feiShuSettingVo != null) {
|
||||
editTextFeishuWebhook.setText(feiShuSettingVo.getWebhook());
|
||||
editTextFeishuSecret.setText(feiShuSettingVo.getSecret());
|
||||
radioGroupFeishuMsgType.check(feiShuSettingVo.getMsgTypeCheckId());
|
||||
editTextFeishuTitle.setText(feiShuSettingVo.getTitleTemplate());
|
||||
if ("text".equals(feiShuSettingVo.getMsgType())) {
|
||||
layoutTitleTemplate.setVisibility(View.GONE);
|
||||
} else {
|
||||
layoutTitleTemplate.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
radioGroupFeishuMsgType.setOnCheckedChangeListener((group, checkedId) -> {
|
||||
if (group != null && checkedId > 0) {
|
||||
layoutTitleTemplate.setVisibility(checkedId == R.id.radioFeishuMsgTypeText ? View.GONE : View.VISIBLE);
|
||||
group.check(checkedId);
|
||||
}
|
||||
});
|
||||
|
||||
Button buttonOk = view1.findViewById(R.id.buttonOk);
|
||||
Button buttonDel = view1.findViewById(R.id.buttonDel);
|
||||
Button buttonTest = view1.findViewById(R.id.buttonTest);
|
||||
@ -1663,12 +1679,15 @@ public class SenderActivity extends AppCompatActivity {
|
||||
String webHook = editTextFeishuWebhook.getText().toString().trim();
|
||||
String secret = editTextFeishuSecret.getText().trim();
|
||||
String msgType = radioGroupFeishuMsgType.getCheckedRadioButtonId() == R.id.radioFeishuMsgTypeText ? "text" : "interactive";
|
||||
String titleTemplate = editTextFeishuTitle.getText().toString().trim();
|
||||
if (!CommonUtil.checkUrl(webHook, false)) {
|
||||
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
|
||||
return;
|
||||
}
|
||||
|
||||
FeiShuSettingVo feiShuSettingVoNew = new FeiShuSettingVo(webHook, secret, msgType);
|
||||
if (TextUtils.isEmpty(titleTemplate)) titleTemplate = "【{{设备名称}}】来自{{来源号码}}的通知";
|
||||
|
||||
FeiShuSettingVo feiShuSettingVoNew = new FeiShuSettingVo(webHook, secret, msgType, titleTemplate);
|
||||
if (isClone || senderModel == null) {
|
||||
SenderModel newSenderModel = new SenderModel();
|
||||
newSenderModel.setName(senderName);
|
||||
@ -1703,6 +1722,7 @@ public class SenderActivity extends AppCompatActivity {
|
||||
String webHook = editTextFeishuWebhook.getText().toString().trim();
|
||||
String secret = editTextFeishuSecret.getText().trim();
|
||||
String msgType = radioGroupFeishuMsgType.getCheckedRadioButtonId() == R.id.radioFeishuMsgTypeText ? "text" : "interactive";
|
||||
String titleTemplate = editTextFeishuTitle.getText().toString().trim();
|
||||
if (!CommonUtil.checkUrl(webHook, false)) {
|
||||
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
|
||||
return;
|
||||
@ -1710,12 +1730,40 @@ public class SenderActivity extends AppCompatActivity {
|
||||
|
||||
try {
|
||||
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
|
||||
SenderFeishuMsg.sendMsg(0, handler, null, webHook, secret, msgType, smsVo.getMobile(), new Date(), smsVo.getSmsVoForSend());
|
||||
SenderFeishuMsg.sendMsg(0, handler, null, webHook, secret, msgType, smsVo.getMobile(), new Date(), smsVo.getTitleForSend(titleTemplate), smsVo.getSmsVoForSend());
|
||||
} catch (Exception e) {
|
||||
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
Button buttonInsertSender = view1.findViewById(R.id.bt_insert_sender);
|
||||
buttonInsertSender.setOnClickListener(view -> {
|
||||
editTextFeishuTitle.setFocusable(true);
|
||||
editTextFeishuTitle.requestFocus();
|
||||
CommonUtil.insertOrReplaceText2Cursor(editTextFeishuTitle, getString(R.string.tag_from));
|
||||
});
|
||||
|
||||
Button buttonInsertExtra = view1.findViewById(R.id.bt_insert_extra);
|
||||
buttonInsertExtra.setOnClickListener(view -> {
|
||||
editTextFeishuTitle.setFocusable(true);
|
||||
editTextFeishuTitle.requestFocus();
|
||||
CommonUtil.insertOrReplaceText2Cursor(editTextFeishuTitle, getString(R.string.tag_card_slot));
|
||||
});
|
||||
|
||||
Button buttonInsertTime = view1.findViewById(R.id.bt_insert_time);
|
||||
buttonInsertTime.setOnClickListener(view -> {
|
||||
editTextFeishuTitle.setFocusable(true);
|
||||
editTextFeishuTitle.requestFocus();
|
||||
CommonUtil.insertOrReplaceText2Cursor(editTextFeishuTitle, getString(R.string.tag_receive_time));
|
||||
});
|
||||
|
||||
Button buttonInsertDeviceName = view1.findViewById(R.id.bt_insert_device_name);
|
||||
buttonInsertDeviceName.setOnClickListener(view -> {
|
||||
editTextFeishuTitle.setFocusable(true);
|
||||
editTextFeishuTitle.requestFocus();
|
||||
CommonUtil.insertOrReplaceText2Cursor(editTextFeishuTitle, getString(R.string.tag_device_name));
|
||||
});
|
||||
}
|
||||
|
||||
//推送加
|
||||
|
@ -11,14 +11,16 @@ public class FeiShuSettingVo implements Serializable {
|
||||
private String webhook;
|
||||
private String secret;
|
||||
private String msgType;
|
||||
private String titleTemplate;
|
||||
|
||||
public FeiShuSettingVo() {
|
||||
}
|
||||
|
||||
public FeiShuSettingVo(String webhook, String secret, String msgType) {
|
||||
public FeiShuSettingVo(String webhook, String secret, String msgType, String titleTemplate) {
|
||||
this.webhook = webhook;
|
||||
this.secret = secret;
|
||||
this.msgType = msgType;
|
||||
this.titleTemplate = titleTemplate;
|
||||
}
|
||||
|
||||
public int getMsgTypeCheckId() {
|
||||
|
@ -346,7 +346,7 @@ public class SendUtil {
|
||||
FeiShuSettingVo feiShuSettingVo = JSON.parseObject(senderModel.getJsonSetting(), FeiShuSettingVo.class);
|
||||
if (feiShuSettingVo != null) {
|
||||
try {
|
||||
SenderFeishuMsg.sendMsg(logId, handError, retryInterceptor, feiShuSettingVo.getWebhook(), feiShuSettingVo.getSecret(), feiShuSettingVo.getMsgType(), smsVo.getMobile(), smsVo.getDate(), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
|
||||
SenderFeishuMsg.sendMsg(logId, handError, retryInterceptor, feiShuSettingVo.getWebhook(), feiShuSettingVo.getSecret(), feiShuSettingVo.getMsgType(), smsVo.getMobile(), smsVo.getDate(), smsVo.getTitleForSend(feiShuSettingVo.getTitleTemplate()), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
|
||||
} catch (Exception e) {
|
||||
LogUtil.updateLog(logId, 0, e.getMessage());
|
||||
Log.e(TAG, "senderSendMsg: feishu error " + e.getMessage());
|
||||
|
@ -9,7 +9,6 @@ import androidx.annotation.NonNull;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.idormy.sms.forwarder.utils.Define;
|
||||
import com.idormy.sms.forwarder.utils.LogUtil;
|
||||
import com.idormy.sms.forwarder.utils.SettingUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -90,7 +89,7 @@ public class SenderFeishuMsg extends SenderBaseMsg {
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
public static void sendMsg(final long logId, final Handler handError, final RetryIntercepter retryInterceptor, String webhook, String secret, String msgType, String from, Date date, String content) throws Exception {
|
||||
public static void sendMsg(final long logId, final Handler handError, final RetryIntercepter retryInterceptor, String webhook, String secret, String msgType, String from, Date date, String title, String content) throws Exception {
|
||||
Log.i(TAG, "sendMsg webhook:" + webhook + " secret:" + secret + " content:" + content);
|
||||
|
||||
if (webhook == null || webhook.isEmpty()) {
|
||||
@ -128,7 +127,7 @@ public class SenderFeishuMsg extends SenderBaseMsg {
|
||||
}
|
||||
|
||||
Log.i(TAG, "requestUrl:" + webhook);
|
||||
final String requestMsg = JSON.toJSONString(textMsgMap).replace("\"${CARD_BODY}\"", buildMsg(from, date, content));
|
||||
final String requestMsg = JSON.toJSONString(textMsgMap).replace("\"${CARD_BODY}\"", buildMsg(from, date, title, content));
|
||||
Log.i(TAG, "requestMsg:" + requestMsg);
|
||||
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
@ -173,8 +172,9 @@ public class SenderFeishuMsg extends SenderBaseMsg {
|
||||
|
||||
}
|
||||
|
||||
private static String buildMsg(String from, Date date, String content) {
|
||||
String msgTitle = jsonInnerStr("【" + SettingUtil.getAddExtraDeviceMark().trim() + "】来自" + from + "的通知");
|
||||
private static String buildMsg(String from, Date date, String title, String content) {
|
||||
//if (TextUtils.isEmpty(title)) title = "【" + SettingUtil.getAddExtraDeviceMark().trim() + "】来自" + from + "的通知";
|
||||
String msgTitle = jsonInnerStr(title);
|
||||
String msgTime = jsonInnerStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(date));
|
||||
String msgFrom = jsonInnerStr(from);
|
||||
String msgContent = jsonInnerStr(content);
|
||||
|
@ -129,6 +129,122 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutTitleTemplate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/feishu_msg_type_interactive_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:text="@string/custom_templates_tips"
|
||||
android:textSize="11sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextFeishuTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:autofillHints=""
|
||||
android:gravity="start|top"
|
||||
android:inputType="text"
|
||||
android:minLines="1"
|
||||
android:text=""
|
||||
tools:ignore="LabelFor,TextFields" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_sender"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_weight="1"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"
|
||||
android:padding="5dp"
|
||||
android:singleLine="true"
|
||||
android:text="@string/insert_sender"
|
||||
android:textSize="11sp"
|
||||
app:backgroundTint="@color/colorBlueGrey"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_extra"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_weight="1"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"
|
||||
android:padding="5dp"
|
||||
android:singleLine="true"
|
||||
android:text="@string/insert_extra"
|
||||
android:textSize="11sp"
|
||||
app:backgroundTint="@color/colorBlueGrey"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_weight="1"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"
|
||||
android:padding="5dp"
|
||||
android:singleLine="true"
|
||||
android:text="@string/insert_time"
|
||||
android:textSize="11sp"
|
||||
app:backgroundTint="@color/colorBlueGrey"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_device_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_weight="1"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"
|
||||
android:padding="5dp"
|
||||
android:singleLine="true"
|
||||
android:text="@string/insert_device_name"
|
||||
android:textSize="11sp"
|
||||
app:backgroundTint="@color/colorBlueGrey"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -147,6 +147,7 @@
|
||||
<string name="feishu_msg_type">Msg Type</string>
|
||||
<string name="feishu_msg_type_text">Text</string>
|
||||
<string name="feishu_msg_type_interactive">Interactive</string>
|
||||
<string name="feishu_msg_type_interactive_title">Interactive Title</string>
|
||||
<string name="Corp_ID">Corp ID</string>
|
||||
<string name="Agent_ID">Agent ID</string>
|
||||
<string name="App_Secret">App Secret</string>
|
||||
|
@ -147,6 +147,7 @@
|
||||
<string name="feishu_msg_type">消息类型</string>
|
||||
<string name="feishu_msg_type_text">纯文本</string>
|
||||
<string name="feishu_msg_type_interactive">消息卡片</string>
|
||||
<string name="feishu_msg_type_interactive_title">标题模板</string>
|
||||
<string name="Corp_ID">企业ID</string>
|
||||
<string name="Agent_ID">应用AgentId</string>
|
||||
<string name="App_Secret">应用Secret</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user