Skip to content

Instantly share code, notes, and snippets.

@dionarya23
Last active November 13, 2020 14:00
Show Gist options
  • Save dionarya23/75e1c3027b56fb66e5794efe290515bd to your computer and use it in GitHub Desktop.
Save dionarya23/75e1c3027b56fb66e5794efe290515bd to your computer and use it in GitHub Desktop.
const express = require("express");
require("dotenv").config();
const { middleware, Client } = require("@line/bot-sdk");
const translate = require("translation-google");
const app = express();
const config = {
channelAccessToken: 'channelAccessToken',
channelSecret: 'channelSecret',
};
const client = new Client(config);
app.post("/webhook", middleware(config), async (req, res) => {
try {
const { type, replyToken, message } = req.body.events[0];
if (type === "message") {
const result = await translate(message.text, {
from: "ar",
to: "id",
});
client.replyMessage(replyToken, {
type: "text",
text: result.text,
});
}
res.status(200).json({message: 'success send message'})
} catch (err) {
console.log("err :", err);
res.status(500).json({
message: "error",
data: err,
});
}
});
app.listen(process.env.PORT || 3000, console.log("Chatbot Runningg...."));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment