Home>
I want to achieve

I want to keep adding variables (maintaining the contents) even if I return a message.

As a usage, for example, a program that adds to the number of times each time it responds and returns the number of times to 0 when the word "reset" is issued. (See below)

User: "Message"
bot: "Reply"
User: Number of times
bot: 1
User: Reset
bot: reset
User: "Message"
bot: "Reply"
User: "Message"
bot: "Reply"
User: Number of times
bot: 2

I also want to count specific words, so I thought that variables were appropriate, but if other methods are good/if there are, I would appreciate it if you could teach me that.

code

Here is the code i am currently using.

var TOKEN = "access token";
var URL = "https://api.line.me/v2/bot/message/reply";
function doPost (event) {
    var request = JSON.parse (event.postData.contents);
    var replyToken = request.events [0] .replyToken;
    var botMessage;// Determine the response text here
    // Contents are omitted
var payload = JSON.stringify ({{
        "replyToken": replyToken,
        "messages": [{
            "type": "text",
            "text": botMessage
        }]
    });
    UrlFetchApp.fetch (URL, {
        "headers": {
            "Content-Type": "application/json;charset = UTF-8",
            "Authorization": "Bearer" + TOKEN
        },
        "method": "post",
        "payload": payload
    });
    return;
}
Supplement

Use Google Drive.
Since I am a beginner, I would appreciate it if you could post an example of the program.

  • Answer # 1

    You can't keep variables.
    I solved it by referring to this and using a spreadsheet.

Related articles