Skip to content

Commit 0a37101

Browse files
authored
Merge pull request #680 from makisukurisu/master
fix: Update `isSupported` check for `sendData` method
2 parents fa9b846 + 503171f commit 0a37101

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

.changeset/wet-geckos-switch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@telegram-apps/sdk": patch
3+
---
4+
5+
Move inline check from sendData to switchInlineQuery.

packages/sdk/src/scopes/utilities/uncategorized/sendData.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { wrapSafe } from '@/scopes/wrappers/wrapSafe.js';
22
import { InvalidArgumentsError } from '@/errors.js';
3-
import { launchParams, postEvent } from '@/globals.js';
3+
import { postEvent } from '@/globals.js';
4+
5+
const METHOD_NAME = 'web_app_data_send';
46

57
/**
68
* Sends data to the bot.
@@ -14,7 +16,6 @@ import { launchParams, postEvent } from '@/globals.js';
1416
* @param data - data to send to bot.
1517
* @throws {FunctionNotAvailableError} The function is not supported
1618
* @throws {FunctionNotAvailableError} The environment is unknown
17-
* @throws {FunctionNotAvailableError} The application must be launched in the inline mode
1819
* @throws {InvalidArgumentsError} Maximum size of data to send is 4096 bytes
1920
* @throws {InvalidArgumentsError} Attempted to send empty data
2021
* @example
@@ -31,13 +32,7 @@ export const sendData = wrapSafe(
3132
? 'Maximum size of data to send is 4096 bytes'
3233
: 'Attempted to send empty data');
3334
}
34-
postEvent('web_app_data_send', { data });
35-
},
36-
{
37-
isSupported() {
38-
return launchParams().tgWebAppBotInline
39-
? undefined
40-
: 'The application must be launched in the inline mode';
41-
},
35+
postEvent(METHOD_NAME, { data });
4236
},
43-
);
37+
{ isSupported: METHOD_NAME },
38+
);

packages/sdk/src/scopes/utilities/uncategorized/switchInlineQuery.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { SwitchInlineQueryChatType } from '@telegram-apps/bridge';
22

3-
import { postEvent } from '@/globals.js';
3+
import { launchParams, postEvent } from '@/globals.js';
44
import { wrapSafe } from '@/scopes/wrappers/wrapSafe.js';
55

66
const SWITCH_INLINE_QUERY_METHOD = 'web_app_switch_inline_query';
@@ -18,6 +18,7 @@ const SWITCH_INLINE_QUERY_METHOD = 'web_app_switch_inline_query';
1818
* @throws {FunctionNotAvailableError} The function is not supported
1919
* @throws {FunctionNotAvailableError} The environment is unknown
2020
* @throws {FunctionNotAvailableError} The SDK is not initialized
21+
* @throws {FunctionNotAvailableError} The application must be launched in the inline mode
2122
* @example
2223
* if (switchInlineQuery.isAvailable()) {
2324
* switchInlineQuery('my query goes here', ['users']);
@@ -31,4 +32,11 @@ export const switchInlineQuery = wrapSafe(
3132
chat_types: chatTypes || [],
3233
});
3334
},
35+
{
36+
isSupported() {
37+
return launchParams().tgWebAppBotInline
38+
? undefined
39+
: 'The application must be launched in the inline mode';
40+
}
41+
}
3442
);

0 commit comments

Comments
 (0)