-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from Telegram-Mini-Apps/feature/request-phone
Feature/request phone
- Loading branch information
Showing
27 changed files
with
652 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@tma.js/sdk": minor | ||
--- | ||
|
||
Implemented MiniApp.requestContact method, reworked MiniApp.requestWriteAccess and MiniApp.requestPhoneAccess methods. Add invokeCustomMethod function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
apps/docs/packages/typescript/tma-js-sdk/components/settings-button.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# `SettingsButton` | ||
|
||
Implements Telegram Mini Apps [Settings Button](../../../../platform/ui/settings-button.md). | ||
|
||
## Initialization | ||
|
||
Component constructor accepts visibility state, Telegram Mini Apps version and optional function | ||
to call Telegram Mini Apps methods. | ||
|
||
```typescript | ||
import { SettingsButton, postEvent } from '@tma.js/sdk'; | ||
|
||
const settingsButton = new SettingsButton(false, '6.3', postEvent); | ||
``` | ||
|
||
## Showing and hiding | ||
|
||
To show and hide the `SettingsButton`, it is required to use `show()` and `hide()` methods. These | ||
methods update the button's `isVisible` property: | ||
|
||
```typescript | ||
settingsButton.show(); | ||
console.log(settingsButton.isVisible); // true | ||
|
||
settingsButton.hide(); | ||
console.log(settingsButton.isVisible); // false | ||
``` | ||
|
||
## Events | ||
|
||
List of events, which could be used in `on` and `off` component instance methods: | ||
|
||
| Event | Listener | Triggered when | | ||
|------------------|----------------------------|--------------------------------| | ||
| click | `() => void` | Settings Button was clicked | | ||
| change | `() => void` | Something in component changed | | ||
| change:isVisible | `(value: boolean) => void` | `isVisible` property changed | | ||
|
||
## Methods support | ||
|
||
List of methods, which could be used in `supports` component instance method: | ||
|
||
- `show` | ||
- `hide` | ||
|
||
```typescript | ||
import { SettingsButton } from '@tma.js/sdk'; | ||
|
||
const settingsButton = new SettingsButton(...); | ||
settingsButton.supports('show'); | ||
settingsButton.supports('hide'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { ExecuteWithOptions } from '~/types/index.js'; | ||
|
||
import type { CustomMethodName, CustomMethodParams } from './methods/index.js'; | ||
import { request } from './request.js'; | ||
|
||
/** | ||
* Invokes known custom method. Returns method execution result. | ||
* @param method - method name. | ||
* @param params - method parameters. | ||
* @param requestId - request identifier. | ||
* @param options - additional options. | ||
*/ | ||
export async function invokeCustomMethod<M extends CustomMethodName>( | ||
method: M, | ||
params: CustomMethodParams<M>, | ||
requestId: string, | ||
options?: ExecuteWithOptions, | ||
): Promise<unknown>; | ||
|
||
/** | ||
* Invokes unknown custom method. Returns method execution result. | ||
* @param method - method name. | ||
* @param params - method parameters. | ||
* @param requestId - request identifier. | ||
* @param options - additional options. | ||
*/ | ||
export function invokeCustomMethod( | ||
method: string, | ||
params: object, | ||
requestId: string, | ||
options?: ExecuteWithOptions, | ||
): Promise<unknown>; | ||
|
||
export async function invokeCustomMethod( | ||
method: string, | ||
params: object, | ||
requestId: string, | ||
options: ExecuteWithOptions = {}, | ||
): Promise<unknown> { | ||
const { result, error } = await request( | ||
'web_app_invoke_custom_method', | ||
{ | ||
method, | ||
params, | ||
req_id: requestId, | ||
}, | ||
'custom_method_invoked', | ||
options, | ||
); | ||
|
||
if (error) { | ||
throw new Error(error); | ||
} | ||
|
||
return result; | ||
} |
Oops, something went wrong.