Skip to content

Instantly share code, notes, and snippets.

class GOL
attr_accessor :size
attr_accessor :board
def initialize(size)
@size = size
reset_board
end
def reset_board
@etrex
etrex / server.js
Last active February 13, 2020 13:46
const bodyParser = require('body-parser');
const express = require('express');
const { bottender } = require('bottender');
const path = require('path');
const app = bottender({
dev: process.env.NODE_ENV !== 'production',
});
const port = Number(process.env.PORT) || 5000;
{
...
"scripts": {
"dev": "nodemon server.js",
"start": "node server.js",
...
},
...
}
server.get('/send-id', (req, res) => {
res.json({ id: process.env.LINE_LIFF_ID });
});
server.get('/liff', (req, res) => {
const filename = path.join(`${__dirname}/liff.html`);
res.sendFile(filename);
});
@etrex
etrex / liff.html
Last active February 13, 2020 13:13
<body>
<button id="button">send test message</button>
<script src="https://static.line-scdn.net/liff/edge/2.1/sdk.js"></script>
<script>
function initializeLiff(myLiffId) {
liff
.init({
liffId: myLiffId,
})
.then(() => {
module.exports = async function App(context) {
const liffUrl = `https://liff.line.me/${process.env.LINE_LIFF_ID}`;
await context.sendText(liffUrl);
};
@etrex
etrex / .env
Created February 13, 2020 13:35
LINE_ACCESS_TOKEN={你的 LINE access token}
LINE_CHANNEL_SECRET={你的 LINE channel secret}
LINE_LIFF_ID={你的 LIFF ID}
@etrex
etrex / lineNotify.js
Last active June 9, 2020 01:57
lineNotify.js
const querystring = require('querystring');
const axios = require('axios');
function getAuthLink(clientId, redirectUrl, state) {
const data = {
response_type: 'code',
client_id: clientId,
redirect_uri: redirectUrl,
scope: 'notify',
state,
const bodyParser = require('body-parser');
const express = require('express');
const { bottender } = require('bottender');
const lineNotify = require('./src/lineNotify');
const app = bottender({
dev: process.env.NODE_ENV !== 'production',
});
const port = Number(process.env.PORT) || 5000;
const { router, route, text } = require('bottender/router');
const lineNotify = require('./lineNotify')
const clientId = process.env.LINE_NOTIFY_CLIENT_ID;
const redirectUri = `${process.env.ROOT_PATH}/callback`;
async function SendSubscriptionGuides(context) {
const uri = lineNotify.getAuthLink(clientId, redirectUri, 'demo');
await context.sendFlex('請點選按鈕訂閱通知:', {