Skip to content

Instantly share code, notes, and snippets.

View tandevmode's full-sized avatar

Warit Wanwithu tandevmode

View GitHub Profile
curl -v -X POST https://api.line.me/v2/bot/message/narrowcast \
-H 'Authorization: Bearer {channel access token}' \
-H 'Content-Type: application/json' \
-d '{
"messages": [
{
"type": "text",
"text": "Hello from Narrowcast API using audience from API and LINE OA Manager"
}
],
curl -v -X POST https://api.line.me/v2/bot/message/narrowcast \
-H 'Authorization: Bearer {channel access token}' \
-H 'Content-Type: application/json' \
-d '{
"messages": [
{
"type": "text",
"text": "Hello from Narrowcast API na ja"
}
],
curl -v -X POST https://api.line.me/v2/bot/audienceGroup/imp \
-H 'Authorization: Bearer {channel access token}' \
-H 'Content-Type: application/json' \
-d '{
"description": "podcastEP1Imp",
"requestId": "c90d2f4b-24cc-4cbe-a7f1-d6c..."
}'
curl -v -X POST https://api.line.me/v2/bot/audienceGroup/click \
-H 'Authorization: Bearer {channel access token}' \
-H 'Content-Type: application/json' \
-d '{
"description": "podcastEP1click",
"requestId": "eec21aab-5747-41fe-95bc-ff7...",
"clickUrl": "https://open.spotify.com/episode/1NIfGNFe2DvymxTx5nofnA"
}'
curl -v -X POST https://api.line.me/v2/bot/audienceGroup/upload \
-H 'Authorization: Bearer {channel access token}' \
-H 'Content-Type: application/json' \
-d '{
"description": "regularCustomerGroup",
"isIfaAudience": "false",
"audiences":[
{
"id":"Uc0a294155281..."
},
const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp();
const request = require("request-promise");
const crypto = require('crypto');
const runtimeOpts = { timeoutSeconds: 4, memory: "2GB" };
const REGION = "asia-northeast1";
const LINE_MESSAGING_API = "https://api.line.me/v2/bot/message";
const LINE_CHANNEL_SECRET = "Your-Channel-Secret";
const GROUP_ID = "Caf6...";
exports.LineBotPush = functions.region(REGION).runWith(runtimeOpts).firestore.document('translations/inputText').onWrite(async (change, context) => {
let latest = change.after.data();
let input = latest.input;
let containsJapanese = input.match(/[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf]/);
if (containsJapanese) {
push(GROUP_ID, latest.translated.th);
} else {
push(GROUP_ID, latest.translated.ja);
}
});
exports.LineWebhook = functions.region(REGION).runWith(runtimeOpts).https.onRequest(async (req, res) => {
let event = req.body.events[0];
if (event.message.type === 'text') {
let input = event.message.text;
await admin.firestore().collection('translations').doc('inputText').set({
input: input
}).then(function () {
console.log("Document successfully written!");
}).catch(function (error) {
console.error("Error writing document: ", error);
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>My LIFF App</title>
</head>
<body>
<p id="scanCode"></p>
<p>
<button id="btnScanCode" onclick="scanCode();">Scan Code</button>
@tandevmode
tandevmode / line-api-playgroud.json
Created August 27, 2018 03:57
NodeRED flow of LINE API Playground
[
{
"id": "b1fd7946.f6a0c8",
"type": "http in",
"z": "9295d104.785ef",
"name": "",
"url": "/playground/api",
"method": "post",
"upload": false,
"swaggerDoc": "",