Skip to content

Commit c881ce8

Browse files
authored
Merge pull request #187 from GleapSDK/feat/custom-action-data
feat: custom actions pass their data to registerCustomAction
2 parents 7ac378b + 6c438a0 commit c881ce8

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## Unreleased
4+
New: custom actions from chat messages and message cards now pass their data to your `Gleap.registerCustomAction` callback as `data` (next to `name` and `shareToken`), with a Messenger that sends it. Callbacks that only read `name` keep working.
5+
36
## 19.3.3
47
Fixed: charts and other SVG graphics could be missing from screenshots. An empty `<style>` inside an `<svg>` was captured as a stylesheet link to `null`, and the screenshot then dropped everything in the svg after it. Inline style sheets now always stay `<style>` elements; linked style sheets whose rules can't be read are still linked.
58

‎index.d.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ export namespace Gleap {
118118
) => string | object | Promise<string | object>
119119
): void;
120120
function registerCustomAction(
121-
customAction: (action: { name: string }) => void
121+
customAction: (action: {
122+
name: string;
123+
/** The action's data (a message button's actionData), when it has some. */
124+
data?: any;
125+
/** The share token of the conversation the action was clicked in. */
126+
shareToken?: string;
127+
}) => void
122128
): void;
123129
function log(message: string, logLevel?: "INFO" | "WARNING" | "ERROR"): void;
124130
/**

‎src/GleapFrameManager.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,11 @@ export default class GleapFrameManager {
12051205
if (data.name === 'run-custom-action') {
12061206
GleapCustomActionManager.triggerCustomAction(data.data, {
12071207
shareToken: data.shareToken,
1208+
// The action's payload (data-action-data / a card button's
1209+
// actionData), sent by Messenger versions that have it.
1210+
...(data.actionData !== undefined && data.actionData !== null
1211+
? { data: data.actionData }
1212+
: {}),
12081213
});
12091214
}
12101215

0 commit comments

Comments
 (0)