From 3831c1b3e7c4a41cfaf11df114074b9b5f544c5b Mon Sep 17 00:00:00 2001 From: techiejd <62455039+techiejd@users.noreply.github.com> Date: Thu, 18 Aug 2022 21:49:49 -0500 Subject: [PATCH] Exports PLATFORMS as Platforms This is necessary to access Platforms in a .ts file. For example: new Payload(Platforms.UNSPECIFIED, payload, {rawPayload: true, sendAsMessage: true}) The platforms are not exposed any where publicly. From the js examples I've seen online, most people access the platforms by WebhookClient.Platform. This doesn't work with ts because WebhookClient.Platform is not an explicit method or a field. The @types/dialogflow-fulfillment exports the platforms; see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f7ec78508c6797e42f87a4390735bc2c650a1bfd/types/dialogflow-fulfillment/index.d.ts#L13 . With that said, it breaks in run time because the .ts is not compiled and the .js does not expose the platforms. Without exposing it, we have the same situation explained here: https://lukasbehal.com/2017-05-22-enums-in-declaration-files/ . See https://github.com/microsoft/TypeScript/issues/37120#issuecomment-592783135 for explanation on this solution. --- src/dialogflow-fulfillment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dialogflow-fulfillment.js b/src/dialogflow-fulfillment.js index b1889d3..b33546b 100644 --- a/src/dialogflow-fulfillment.js +++ b/src/dialogflow-fulfillment.js @@ -560,4 +560,4 @@ class WebhookClient { } } -module.exports = {WebhookClient, Text, Card, Image, Suggestion, Payload}; +module.exports = {WebhookClient, Text, Card, Image, Suggestion, Payload, Platforms: PLATFORMS};