potato 回声机器人

  • sauween 
var TOKEN = '机器人的token';
var BASE_URL = 'https://api.sydney.im:8443/' + TOKEN + '/';
function doGet(e) {
    const code = {
        res: true
    }
    return ContentService.createTextOutput(JSON.stringify(code))
        .setMimeType(ContentService.MimeType.JSON);
}
function doPost(e) {
    var bodys = JSON.parse(e.postData.contents);
    Logger.log(bodys)
    mongo.insert("nowmoer", e)

    for (var i = 0; i < bodys.length; i++) {
        body = bodys[i];
        if (body) {
            mongo.insert("nowmoer", body)
            payload = preparePayload(body);
            toPotato(payload)
        }
    }
}
function toPotato(payload) {
    Logger.log(payload)
    if (Array.isArray(payload)) {
        payloads = payload;
    } else {
        payloads = [payload];
    }
    Logger.log(payloads)
    for (var i = 0; i < payloads.length; i++) {
        payload = payloads[i];
        if (payload) {
            var res = postPotato(payload);
            Logger.log(res)
        }
    }
}
function setWebhook() {  //绑定setWebhook函数,请运行这个函数
    var setWebhook = {
        method: 'setWebhook',
        payload: {
            url: '你的网址'
        }
    }
    Logger.log(postPotato(setWebhook))
}
function postPotato(payload) {
    var data = {
        'contentType': 'application/json',
        "method": "post",
        "payload": JSON.stringify(payload.payload)
    }

    var response = UrlFetchApp.fetch(BASE_URL + payload.method, data);
    var res = JSON.parse(response);
    mongo.insert("nowmoer", res)
    return res;
}
function preparePayload(body) {
    if (body.message && body.message.text) {
        if (body.message.from.id = 10240107) {
            return null
        }
        var sendTextMessage = {
            method: 'sendTextMessage',
            payload: {
                "chat_type": body.message.chat.type,
                "chat_id": body.message.chat.id,
                "text": mest,
                "markdown": true,
            }
        }
        var mest = body.message.text;
        if (mest == '小掌门') {
            var zhangmeng = ['你好', '',]
            sendTextMessage.payload.text = ''
            return sendTextMessage
        }
        if (mest) {
            sendTextMessage.payload.text = mest
            return sendTextMessage
        }
    }
}

《potato 回声机器人》有2个想法

发表评论

电子邮件地址不会被公开。 必填项已用*标注