This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
if(event.message.text === 'register') { | |
let access_token = await issue_access_token(); | |
access_token = JSON.parse(access_token); | |
// 7. Initialize LINE Header | |
// 8. Store Access Token to Real Time Database | |
// 9. Reply result to User Chat Room | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const initialLINE = async(token_type, token) => { | |
LINE_HEADER = { | |
"Content-Type": "application/json", | |
"Authorization": `${token_type} ${token}` | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
if(event.message.text === 'register') { | |
let access_token = await issue_access_token(); | |
access_token = JSON.parse(access_token); | |
await initialLINE(access_token['token_type'], access_token['access_token']); | |
// 8. Store Access Token to Real Time Database | |
// 9. Reply result to User Chat Room | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
if(event.message.text === 'register') { | |
let access_token = await issue_access_token(); | |
access_token = JSON.parse(access_token); | |
await initialLINE(access_token['token_type'], access_token['access_token']); | |
await admin.database().ref('token').child(event.source.userId).set(access_token); | |
// 9. Reply result to User Chat Room | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const reply = (token, payload) => { | |
return request.post({ | |
uri: `${LINE_MESSAGING_API}/reply`, | |
headers: LINE_HEADER, | |
body: JSON.stringify({ | |
replyToken: token, | |
messages: [payload] | |
}) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
if(event.message.text === 'register') { | |
let access_token = await issue_access_token(); | |
access_token = JSON.parse(access_token); | |
await initialLINE(access_token['token_type'], access_token['access_token']); | |
await admin.database().ref('token').child(event.source.userId).set(access_token); | |
reply(event.replyToken, { | |
type: 'text', | |
text: '\uDBC0\uDC7F ลงทะเบียน token เรียบร้อยแล้ว เอาไปใช้ได้เลย\n\n' + JSON.stringify(access_token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
} else if(event.message.text === 'revoke') { | |
let token = await admin.database().ref('token').child(event.source.userId).once('value'); | |
// 11. Initialize LINE Header | |
// 12. Remove Access Token from RTDB | |
// 13. Reply result to User Chat Room | |
// 14. Revoke Access Token | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
} else if(event.message.text === 'revoke') { | |
let token = await admin.database().ref('token').child(event.source.userId).once('value'); | |
await initialLINE(token.val().token_type, token.val().access_token ); | |
// 12. Remove Access Token from RTDB | |
// 13. Reply result to User Chat Room | |
// 14. Revoke Access Token | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.AccessTokenBot = functions.region(region).runWith(runtimeOpts).https.onRequest(async (req, res) => { | |
let event = req.body.events[0] | |
switch (event.type) { | |
case 'message': | |
if (event.message.type === 'text') { | |
if(event.message.text === 'register') { | |
// 6. Call API for Create Access Token | |
// 7. Initialize LINE Header | |
// 8. Store Access Token to Real Time Database | |
// 9. Reply result to User Chat Room |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
} else if(event.message.text === 'revoke') { | |
let token = await admin.database().ref('token').child(event.source.userId).once('value'); | |
await initialLINE(token.val().token_type, token.val().access_token ); | |
await admin.database().ref('token').child(event.source.userId).remove(); | |
// 13. Reply result to User Chat Room | |
// 14. Revoke Access Token | |
} | |
... |