I installed gatsby-plugin-support-chat and followed the tutorial from here (https://www.gatsbyjs.com/plugins/gatsby-plugin-support-chat).
When I run npx ngrok http 8000, and try to send message in the chat-bot, then it occurs 500 error like this.
Module parse failed: Unexpected token (4:13)
You may need an appropriate loader to handle this file type, currently no
loaders are configured to process this file. See
https://webpack.js.org/concepts#loaders
| import { WebClient } from "@slack/web-api"
|
> let channelID: string = process.env.CHANNEL_ID
| let token: string = process.env.SLACK_TOKEN
Absolutely, I added 2 above env variables in the env.development file and checked them using the console in the component file.
This error just occurs in the \node_modules\gatsby-plugin-support-chat\src\api\gatsby-plugin-support-chat\send-message.ts.
The content of send-message.ts is like this
import { GatsbyFunctionRequest, GatsbyFunctionResponse } from "gatsby"
import { WebClient } from "@slack/web-api"
let channelID: string = process.env.CHANNEL_ID
let token: string = process.env.SLACK_TOKEN
const web = new WebClient(token)
interface SlackRequest {
channel: string
text: string
thread_ts?: string
}
export default async function handler(
req: GatsbyFunctionRequest,
res: GatsbyFunctionResponse
) {
if (req.method != "POST") {
return res.status(401).json({
message: "Use post method",
})
}
let requestData: SlackRequest
try {
if (req.body.thread_ts != null) {
requestData = {
channel: channelID,
text: req.body.message,
thread_ts: req.body.thread_ts,
}
} else {
requestData = { channel: channelID, text: req.body.message }
}
const result = await web.chat.postMessage(requestData).then(res => {
return res
})
res.json(result)
} catch (error) {
console.log(error)
res.status(500).send(error)
}
}
Does anyone know this issue solution? Thanks