需要用到的链接如下:

https://api.telegram.org/bot918525260:AAGpkBMJ1YuX0Qq3r8y0JOPXBDgNibJqoJ0/setwebhook?url=    用来关联群组 后面是编码了之后的  例如
https://api.telegram.org/bot918525260:AAGpkBMJ1YuX0Qq3r8y0JOPXBDgNibJqoJ0/setwebhook?url=https%3A%2F%2Fscript.google.com%2Fmacros%2Fs%2FAKfycbyeI5AOc42UjZRnLI-Nr_h2KKe0DWceLK2sSzL8JFKUXUnTV5s%2Fexec

https://www.url-encode-decode.com/ 用来编解码

https://script.google.com/home 放代码 发布用

首先需要打开https://script.google.com/home

代码如下

function doGet(e){
  return HtmlService.createHtmlOutput("Hello World!! No, this link should be hidden!!!");
   
 //  return HtmlService.createHtmlOutputFromFile('Index');
}
 
 
function doPost(e){
  var body = JSON.parse(e.postData.contents);
   
  body.message.chat.id = body.message.chat.id + '';
 
  var payload = preparePayload(body);
  var data = {    
    "method": "post",
    "contentType": 'application/json',
    "payload": JSON.stringify(payload),
  }
   
  UrlFetchApp.fetch("https://api.telegram.org/bot682267360:AAHmjSil8oylavD2pENLLpcMU1svaD7mVeA/", data);
}
 
function getName(user) {
  var name = user.first_name;
  if (user.last_name) {
    name += " " + user.last_name;
  }
 
  return name;
}
 
function escapeMarkDown(toEscapeMsg) {
  var escapedMsg = toEscapeMsg
  .replace(/_/g, "\\_")
  .replace(/\*/g, "\\*")
  .replace(/\[/g, "\\[")
  .replace(/`/g, "\\`");
    return escapedMsg;
 
}
 
 
function getMentionName(user) {
  var username = user.username;
  var mentionName = "";
 
  var name = getName(user);
  if (!name) {
    name = "神秘人";
  }
 
  // if (!username) {
    mentionName = getMarkDownUserUrl(escapeMarkDown(name), user.id);
  // } else {
  //   mentionName = "[" + escapeMarkDown(name) + "](@" + escapeMarkDown(username) + ")";
  // }
 
  return mentionName;
}
 
function getMarkDownUserUrl(userName, userId) {
  return "[" + userName + "](tg://user?id=" + userId + ")";
}
 
 
function preparePayload(body){
  var payload;
   
  if (body.message.new_chat_member) {
     payload = {
        "method": "sendMessage",
        "chat_id": body.message.chat.id,
        "text": "你好, 欢迎加入本群",
        "parse_mode": "Markdown",
        "disable_web_page_preview": true,
      } 
       
      payload.text = "你好!" + getMentionName(body.message.new_chat_member) + " 欢迎加入本群";
      return payload;
  }
   
  if (body.message.left_chat_member) {
     payload = {
        "method": "sendMessage",
        "chat_id": body.message.chat.id,
        "text": "你好, 欢迎加入本群",
        "parse_mode": "Markdown",
        "disable_web_page_preview": true,
      } 
       
      payload.text = getMentionName(body.message.left_chat_member) + "君, 一路走好!";
      return payload;
  }
   
   if (body.message.pinned_message) {
    payload = {
        "method": "sendMessage",
        "chat_id": body.message.chat.id,
        "text": "你好, 欢迎加入本群",
        "parse_mode": "Markdown",
        "disable_web_page_preview": true,
      } 
    var whoPinned = getName(body.message.from);
    var whoOwned = getName(body.message.pinned_message.from);
 
    payload.text = whoPinned + "置顶了消息:\n\n" + body.message.pinned_message.text
      + "\n\n"
      + "本 BOT 代表" + whoOwned + "感谢您"
      ;
    return payload;
  }
 
 
  body.message.text = body.message.text.toLowerCase();
  body.message.text = body.message.text.replace(/@temptestbot2/g, '');
   
  var paras = body.message.text.trim().split(" ");
  // remove empty strings
  paras = paras.filter(function(para){
    if (para){
      return true;
    }
  });
   
   
   
  if (body.message.text){
   
      payload = {
        "method": "sendMessage",
        "chat_id": body.message.chat.id,
        "text": "你好, 欢迎使用本机器人, 本机器人现在只认识颜色。",
        "parse_mode": "Markdown",
        "disable_web_page_preview": true,
      } 
       
      if(body.message.text.indexOf("/help") === 0){      
         payload.text = "你好, 欢迎使用本机器人, 本机器人现在只认识颜色。";
         return payload;
      }
       
      if(body.message.text.indexOf("/colors") === 0){   
         payload.text = "红\n 黄\n 蓝";        
         return payload;
      }
       
      if(body.message.text.indexOf("/list") === 0){ 
         if (paras[1]){
           switch (paras[1].toLowerCase()){
             case "people":  
               if (paras[2]){
                 if ("JS 神技能".toLowerCase().indexOf(paras[2]) >= 0){
                   payload.text = "JS 神技能 - https://www.youtube.com/channel/UC6tPP3jOTKgjqfDgqMsaG4g";
                 }
                 if ("悟空的日常".toLowerCase().indexOf(paras[2]) >= 0){
                   payload.text = "悟空的日常 - https://www.youtube.com/channel/UCii04BCvYIdQvshrdNDAcww";
                 }
                 if ("YuFeng Deng".toLowerCase().indexOf(paras[2]) >= 0){
                   payload.text = "YuFeng Deng - https://www.youtube.com/channel/UCG6xoef2xU86hnrCsS5m5Cw";
                 }
               } else {                 
                 payload.text = "JS 神技能\n"
                   + "悟空的日常\n"
                   + "YuFeng Deng\n";        
                   return payload;
                }
               break;
             default:  
               payload.text = "红\n 黄\n 蓝";            
             break;
           }
                 
           return payload;
         } else {         
           payload.text = "*JS 神技能*\n"
             + "[悟空的日常](https://www.youtube.com/channel/UCii04BCvYIdQvshrdNDAcww)\n"
             + "[*YuFeng Deng*](https://www.youtube.com/channel/UCG6xoef2xU86hnrCsS5m5Cw)\n"
             + "_YuFeng Deng_\n"
             + "`01|" + "UCii04BCvYIdQvshrdNDAcww" + " | `\n"
             + "`02|" + "UCG6xoef2xU86hnrCsS5m5Cw" + " | `\n"
             + "```javascript\n"
             + 'payload = {\n'
             + '    "method": "sendMessage",\n'
             + '    "chat_id": body.message.chat.id,\n'
             + '    "text": body.message.text,\n'
             + '}'
             + "```"
             ;
                        
            var inlineKeyboardMarkup = {};
            inlineKeyboardMarkup.inline_keyboard = [];
            var keyboardRow = [];
            var keyboardButton1 = {
                text: "按钮 1",
                url: "https://www.google.com"
            };
             
            var keyboardButton2 = {
                text: "按钮 2",
                url: "https://www.google.com"
            };
             
            var keyboardRow2 = [];
            var keyboardButton3 = {
                text: "按钮 3",
                url: "https://www.google.com"
            };
             
            var keyboardButton4 = {
                text: "按钮 4",
                url: "https://www.google.com"
            };
 
            keyboardRow.push(keyboardButton1);
            keyboardRow.push(keyboardButton2);
             
            keyboardRow2.push(keyboardButton3);
            keyboardRow2.push(keyboardButton4);
            inlineKeyboardMarkup.inline_keyboard.push(keyboardRow);
            inlineKeyboardMarkup.inline_keyboard.push(keyboardRow2);
            payload.reply_markup = inlineKeyboardMarkup;
 
        
           return payload;
         }
      }
       
 
   
      payload = {
          "method": "sendMessage",
          "chat_id": body.message.chat.id,
          "text": body.message.text,
      } 
     
  }
  else if (body.message.sticker){
    payload = {
      "method": "sendSticker",
      "chat_id": body.message.chat.id,
      "sticker": body.message.sticker.file_id
    }
   }
  else if (body.message.photo){
    array = body.message.photo;
    text = array[1];
    payload = {
      "method": "sendPhoto",
      "chat_id": body.message.chat.id,
      "photo": text.file_id
    }
   }
    else {
    payload = {
      "method": "sendMessage",
      "chat_id": body.message.chat.id,
      "text": "Try other stuff"
    }
   }
  return payload
}

进入之后 放进去代码 改一下bot的token
2019-11-24T09:12:05.png
改一下 new_chat_member payload.text 内容就好 发布为网络应用 所有人匿名都可以访问。

2019-11-24T09:12:31.png
2019-11-24T09:12:42.png

点击查看权限

2019-11-24T09:12:53.png

继续点击下一步,
2019-11-24T09:13:32.png

发布成功有一个url 谷歌浏览器打开 会有hello world等信息 就成功了。

https://script.google.com/macros/s/AKfycbwPhhER7jTC9QFjeyk1zhIY-piF0yWZNxXA8xiEER4aukRFJK2A/exec

然后继续复制exec结尾的这段url 去编解码 编码 encode

https://www.url-encode-decode.com/    编码完成之后google浏览器访问 https://api.telegram.org/bot964313453:AAEjCkJ72n-36i_emfl0a2UQ9Nw-kdQyLPo/setwebhook?url=

完整的url

https://api.telegram.org/bot806329752:AAGSkuBN_Q4gsfdGwfqzIpFLFLjHd4qbsS8/setwebhook?url=https%3A%2F%2Fscript.google.com%2Fmacros%2Fs%2FAKfycbwPhhER7jTC9QFjeyk1zhIY-piF0yWZNxXA8xiEER4aukRFJK2A%2Fexec

bot后面是机器人的toke
这个url=后面写你编码之后的地址 访问看到 ok true result 等信息就成功了 把机器人拉进群 他就会自动欢迎入群的人了

取消镜像功能版代码如下

function doGet(e){
  return HtmlService.createHtmlOutput("Hello World!! No, this link should be hidden!!!");
   
 //  return HtmlService.createHtmlOutputFromFile('Index');
}
 
 
function doPost(e){
  var body = JSON.parse(e.postData.contents);
   
  body.message.chat.id = body.message.chat.id + '';
 
  var payload = preparePayload(body);
  var data = {    
    "method": "post",
    "contentType": 'application/json',
    "payload": JSON.stringify(payload),
  }
   
  UrlFetchApp.fetch("https://api.telegram.org/bot823364686:AAGZ7rfDbT6khbCqDCONMVoTXwHXaKn8TW0/", data);
}
 
function getName(user) {
  var name = user.first_name;
  if (user.last_name) {
    name += " " + user.last_name;
  }
 
  return name;
}
 

function escapeMarkDown(toEscapeMsg) {
  var escapedMsg = toEscapeMsg
  .replace(/_/g, "\\_")
  .replace(/\*/g, "\\*")
  .replace(/\[/g, "\\[")
  .replace(/`/g, "\\`");
    return escapedMsg;
}
 
 
function getMentionName(user) {
  var username = user.username;
  var mentionName = "";
 
  var name = getName(user);
  if (!name) {
    name = "神秘人";
  }
 
  // if (!username) {
    mentionName = getMarkDownUserUrl(escapeMarkDown(name), user.id);
  // } else {
  //   mentionName = "[" + escapeMarkDown(name) + "](@" + escapeMarkDown(username) + ")";
  // }
 
  return mentionName;
}
 
function getMarkDownUserUrl(userName, userId) {
  return "[" + userName + "](tg://user?id=" + userId + ")";
}
 
 
function preparePayload(body){
  var payload;
   
  if (body.message.new_chat_member) {
     payload = {
        "method": "sendMessage",
        "chat_id": body.message.chat.id,
        "text": "你好, 欢迎加入本群",
        "parse_mode": "Markdown",
        "disable_web_page_preview": true,
      } 
       
      payload.text = "你好!" + getMentionName(body.message.new_chat_member) + ", 11";
      return payload;
  }
   
  if (body.message.left_chat_member) {
     payload = {
        "method": "sendMessage",
        "chat_id": body.message.chat.id,
        "text": "你好, 欢迎加入本群",
        "parse_mode": "Markdown",
        "disable_web_page_preview": true,
      } 
       
      payload.text = getMentionName(body.message.left_chat_member) + "君, 一路走好!";
      return payload;
  }
   
   if (body.message.pinned_message) {
    payload = {
        "method": "sendMessage",
        "chat_id": body.message.chat.id,
        "text": "你好, 欢迎加入本群",
        "parse_mode": "Markdown",
        "disable_web_page_preview": true,
      } 
    var whoPinned = getName(body.message.from);
    var whoOwned = getName(body.message.pinned_message.from);
 
    payload.text = whoPinned + "置顶了消息:\n\n" + body.message.pinned_message.text
      + "\n\n"
      + "本 BOT 代表" + whoOwned + "感谢您"
      ;
    return payload;
  }
 
 
  body.message.text = body.message.text.toLowerCase();
  body.message.text = body.message.text.replace(/@temptestbot2/g, '');
   
  var paras = body.message.text.trim().split(" ");
  // remove empty strings
  paras = paras.filter(function(para){
    if (para){
      return true;
    }
  });
   
   
   
  if (body.message.text){
   

       

      if(body.message.text.indexOf("/colors") === 0){   
         payload.text = "红\n 黄\n 蓝";        
         return payload;
      }
       
      if(body.message.text.indexOf("/list") === 0){ 
         if (paras[1]){
           switch (paras[1].toLowerCase()){
             case "people":  
               if (paras[2]){
                 if ("JS 神技能".toLowerCase().indexOf(paras[2]) >= 0){
                   payload.text = "JS 神技能 - https://www.youtube.com/channel/UC6tPP3jOTKgjqfDgqMsaG4g";
                 }
                 if ("悟空的日常".toLowerCase().indexOf(paras[2]) >= 0){
                   payload.text = "悟空的日常 - https://www.youtube.com/channel/UCii04BCvYIdQvshrdNDAcww";
                 }
                 if ("YuFeng Deng".toLowerCase().indexOf(paras[2]) >= 0){
                   payload.text = "YuFeng Deng - https://www.youtube.com/channel/UCG6xoef2xU86hnrCsS5m5Cw";
                 }
               } else {                 
                 payload.text = "JS 神技能\n"
                   + "悟空的日常\n"
                   + "YuFeng Deng\n";        
                   return payload;
                }
               break;
             default:  
               payload.text = "红\n 黄\n 蓝";            
             break;
           }
                 
           return payload;
         } else {         
           payload.text = "*JS 神技能*\n"
             + "[悟空的日常](https://www.youtube.com/channel/UCii04BCvYIdQvshrdNDAcww)\n"
             + "[*YuFeng Deng*](https://www.youtube.com/channel/UCG6xoef2xU86hnrCsS5m5Cw)\n"
             + "_YuFeng Deng_\n"
             + "`01|" + "UCii04BCvYIdQvshrdNDAcww" + " | `\n"
             + "`02|" + "UCG6xoef2xU86hnrCsS5m5Cw" + " | `\n"
             + "```javascript\n"
             + 'payload = {\n'
             + '    "method": "sendMessage",\n'
             + '    "chat_id": body.message.chat.id,\n'
             + '    "text": body.message.text,\n'
             + '}'
             + "```"
             ;
                        
            var inlineKeyboardMarkup = {};
            inlineKeyboardMarkup.inline_keyboard = [];
            var keyboardRow = [];
            var keyboardButton1 = {
                text: "按钮 1",
                url: "https://www.google.com"
            };
             
            var keyboardButton2 = {
                text: "按钮 2",
                url: "https://www.google.com"
            };
             
            var keyboardRow2 = [];
            var keyboardButton3 = {
                text: "按钮 3",
                url: "https://www.google.com"
            };
             
            var keyboardButton4 = {
                text: "按钮 4",
                url: "https://www.google.com"
            };
 
            keyboardRow.push(keyboardButton1);
            keyboardRow.push(keyboardButton2);
             
            keyboardRow2.push(keyboardButton3);
            keyboardRow2.push(keyboardButton4);
            inlineKeyboardMarkup.inline_keyboard.push(keyboardRow);
            inlineKeyboardMarkup.inline_keyboard.push(keyboardRow2);
            payload.reply_markup = inlineKeyboardMarkup;
 
        
           return payload;
         }
      }
       
 

   }

  return payload
}
Last modification:December 7th, 2019 at 05:19 am
如果觉得我的文章对你有用,请随意赞赏