Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
使用 Tasker 实现安卓的短信转发
// cspell:disable
// function global(param) {
// if (param == "SMSRN") return "MorFans.cn";
// if (param == "SMSRF") return "魔帆博客";
// if (param == "SMSRD") return "9-16-21";
// if (param == "SMSRT") return "14.45";
// if (param == "SMSRB") return "【魔帆博客】您的登录验证码是 6666,请于-30分钟内填写。如非本人操作,请试试加入咱们的讨论群,加入咱们。群号:179020064 301661143";
// }
let apiKey = "填写你的 bot token";
let chatID = "你的UID";
let apiUrl = "api.telegram.org";
// 处理发件人姓名
let senderName = global('SMSRN');
const re = /\d*/g;
if (senderName.match(re)[0].length > 0) {
senderName = "";
}
// 处理数字
let senderBody = global('SMSRB')
const digRe = /(\d+-\d+-\d+)|(\d+-\d+)|(\d+)/gm
senderBody = senderBody.replace(digRe, function (match) {
return `<code>${match}</code>`;
});
const Message = `✉ <b>${global('SMSRF')} ${(senderName != "") ? "(#" + (senderName) + ")" : ""}</b>\n时间:${global('SMSRD')} ${global('SMSRT').replace('.', ':')}\n\n${senderBody}`;
let myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
let urlencoded = new URLSearchParams();
urlencoded.append("chat_id", chatID);
urlencoded.append("text", Message);
urlencoded.append("parse_mode", "HTML");
let requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};
fetch(`https://${apiUrl}/bot${apiKey}/sendMessage`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment