line-bot-sdk-nodejs
line-bot-sdk-nodejs copied to clipboard
Property 'replyToken' does not exist on type 'WebhookEvent' in typescript
export default async (event: WebhookEvent): Promise<any> => {
console.log('event', event);
const msg: TextMessage = { type: "text", text: 'hello world!' };
return client.replyMessage(event.replyToken, msg);
}
i already check in this lib about WebhookEvent type. it already define 'replyToken' as a property already but i don't know why it still complain.
i think it define here at https://github.com/line/line-bot-sdk-nodejs/blob/master/lib/types.ts#L98
WebhookEvent is not derived from ReplyableEvent.
export type WebhookEvent =
| MessageEvent
| FollowEvent
| UnfollowEvent
| JoinEvent
| LeaveEvent
| MemberJoinEvent
| MemberLeaveEvent
| PostbackEvent
| BeaconEvent
| AccountLinkEvent
| DeviceLinkEvent
| DeviceUnlinkEvent;
For example, UnfollowEvent is not replyable.
As a result, you need to check the type of event before taking a reply token.
function handleEvent(event: line.WebhookEvent) {
if (event.type !== 'message' || event.message.type !== 'text') {
// ignore non-text-message event
return Promise.resolve(null);
}
console.log(`Received message: ${event.message.text}`);
// create a echoing text message
const echo: line.TextMessage = { type: 'text', text: event.message.text };
// use reply API
return client.replyMessage(event.replyToken, echo);
}
@tokuhirom ahh i got it thank a lot