Last active
November 13, 2020 14:00
-
-
Save dionarya23/75e1c3027b56fb66e5794efe290515bd to your computer and use it in GitHub Desktop.
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 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