Skip to content

Commit

Permalink
Merge pull request #100 from Telegram-Mini-Apps/feature/router
Browse files Browse the repository at this point in the history
New big update
  • Loading branch information
heyqbnk authored Sep 29, 2023
2 parents 92512c1 + 2ace529 commit a0ab76f
Show file tree
Hide file tree
Showing 205 changed files with 1,575 additions and 997 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-falcons-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tma.js/navigation": patch
---

Implement new package
17 changes: 17 additions & 0 deletions .changeset/small-spoons-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@tma.js/init-data-node": patch
"react-sdk-example": patch
"solid-sdk-example": patch
"@tma.js/event-emitter": patch
"@tma.js/util-types": patch
"@tma.js/init-data": patch
"@tma.js/sdk-react": patch
"@tma.js/sdk-solid": patch
"@tma.js/parsing": patch
"@tma.js/bridge": patch
"@tma.js/colors": patch
"@tma.js/utils": patch
"@tma.js/sdk": patch
---

Update docs URLs. Rename packages to @tma.js. Update deps
5 changes: 5 additions & 0 deletions .changeset/tough-deers-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tma.js/logger": patch
---

Implement new package
2 changes: 1 addition & 1 deletion apps/docs/docs/apps-communication/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ environment for the Web App. For developers, it is enough to know, that this
environment is web-based, but nevertheless, each of them has its own
communication way between the Telegram application and Web App.

To be more accurate, Telegram Web Apps is not new technology even in the world
To be more accurate, Telegram Mini Apps is not new technology even in the world
of Telegram. Messenger already has such technology as Telegram Games, which is,
internally, almost the same platform as Web Apps. At least, it uses the same way
of communication with the front-end app.
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/docs/guides/creating-new-app.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Creating new app

In this article, we will delve into the process of developing a new application on the
Telegram Web Apps platform, we will find out exactly what actions need to be performed to create it,
Telegram Mini Apps platform, we will find out exactly what actions need to be performed to create it,
as well as give advice on improving the process of creating an application.

The process of creating an application usually consists of the following basic steps:
Expand Down Expand Up @@ -31,7 +31,7 @@ bots, the bot [BotFather](https://t.me/botfather) and use the command
`/newbot`, then go through the proposed process, specifying all the necessary data.

When the bot is created, it is required then to use the command `/newapp` and again go
through the procedure of creating another entity - the Telegram Web Apps application,
through the procedure of creating another entity - the Telegram Mini Apps application,
linking it to the Telegram bot. From now on, the created application will
be available via a direct link of the form `https://t.me/{mybot}/{myapp}`.

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/docs/introduction/about-platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 1

# About platform

Telegram Web Apps is a technology created by developers of the famous messenger
Telegram Mini Apps is a technology created by developers of the famous messenger
Telegram.
The main it’s purpose is to provide developers more flexible communication
channel with Telegram users.
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/docs/launch-params/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Telegram to the TWA application.

### `tgWebAppVersion`

The current Telegram Web Apps version used by the native application. This
The current Telegram Mini Apps version used by the native application. This
parameter is important to use, for example, before calling the
TWA [methods](../apps-communication/methods.mdx) to make sure, they are
supported.
Expand Down
12 changes: 6 additions & 6 deletions apps/docs/docs/libraries/init-data-golang.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ sidebar_position: 100

# init-data-golang

The package provides utilities to work with the initialization data of Telegram Web Apps. To learn more about the initialization data and its usage, please refer to the [documentation](../launch-params/init-data.mdx).
The package provides utilities to work with the initialization data of Telegram Mini Apps. To learn more about the initialization data and its usage, please refer to the [documentation](../launch-params/init-data.mdx).

## Installation

```bash
go get github.com/telegram-web-apps/init-data-golang
go get github.com/telegram-mini-apps/init-data-golang
```

## Validation
Expand All @@ -21,7 +21,7 @@ package main

import (
"fmt"
"github.com/Telegram-Web-Apps/init-data-golang"
"github.com/Telegram-Mini-Apps/init-data-golang"
"time"
)

Expand Down Expand Up @@ -50,7 +50,7 @@ package main

import (
"fmt"
"github.com/Telegram-Web-Apps/init-data-golang"
"github.com/Telegram-Mini-Apps/init-data-golang"
)

func main() {
Expand All @@ -73,7 +73,7 @@ package main

import (
"fmt"
"github.com/Telegram-Web-Apps/init-data-golang"
"github.com/Telegram-Mini-Apps/init-data-golang"
"time"
)

Expand Down Expand Up @@ -101,4 +101,4 @@ func main() {

## GoDoc

To see GoDoc documentation, visit [this link](https://pkg.go.dev/github.com/telegram-web-apps/init-data-golang).
To see GoDoc documentation, visit [this link](https://pkg.go.dev/github.com/telegram-mini-apps/init-data-golang).
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
sidebar_label: "@twa.js/bridge"
sidebar_label: "@tma.js/bridge"
sidebar_position: 1
---

# @twa.js/bridge
# @tma.js/bridge

<LibraryBadges pkg={'@twa.js/bridge'}/>
<LibraryBadges pkg={'@tma.js/bridge'}/>

The package provides utilities to simplify communication between web applications and the Telegram native application. It also addresses cross-platform data differences, safeguarding developers' code and saving their time.

Developers can utilize this package to create their software development kit (SDK), as it offers the utmost level of control over cross-application communication.

## Installation

<NpmInstall pkg={'@twa.js/bridge'}/>
<NpmInstall pkg={'@tma.js/bridge'}/>

## Calling methods

To call the Telegram Web Apps methods, you should use `postEvent` function:
To call the Telegram Mini Apps methods, you should use `postEvent` function:

```typescript
import { postEvent } from '@twa.js/bridge';
import { postEvent } from '@tma.js/bridge';

postEvent('web_app_setup_back_button', {is_visible: true});
```
Expand All @@ -34,7 +34,7 @@ This function automatically finds the correct way to send this event based on th
To start working with events, we could use `on` and `off` functions. Here is how basic `on` function usage looks like:

```typescript
import { on } from '@twa.js/bridge';
import { on } from '@tma.js/bridge';

// Start listening to "viewport_changed" event. Returned value
// is a function, which removes this event listener.
Expand All @@ -49,7 +49,7 @@ removeListener();
To stop listening to events, you could alternatively use `off` function:

```typescript
import { on, off, EventListener } from '@twa.js/bridge';
import { on, off, EventListener } from '@tma.js/bridge';

const listener: EventListener<'viewport_changed'> = payload => {
console.log('Viewport changed:', payload);
Expand All @@ -68,7 +68,7 @@ To listen to all events sent from the native Telegram application,
we utilize such functions as `subscribe` and `unsubscribe`:

```typescript
import { subscribe, unsubscribe, GlobalEventListener } from '@twa.js/bridge';
import { subscribe, unsubscribe, GlobalEventListener } from '@tma.js/bridge';

const listener: GlobalEventListener = (event, data) => {
console.log('Received event', event, 'with data', data);
Expand All @@ -83,10 +83,10 @@ unsubscribe(listener);

## Checking method support

`postEvent` function itself is not checking if specified method supported by current native Telegram application. To do this, we could use `supports` function which accepts Telegram Web Apps method name and current platform version:
`postEvent` function itself is not checking if specified method supported by current native Telegram application. To do this, we could use `supports` function which accepts Telegram Mini Apps method name and current platform version:

```typescript
import { supports } from '@twa.js/bridge';
import { supports } from '@tma.js/bridge';

supports('web_app_trigger_haptic_feedback', '6.0'); // false
supports('web_app_trigger_haptic_feedback', '6.1'); // true
Expand All @@ -105,7 +105,7 @@ messages related to events handling. To change debug mode, use `setDebug`
function:

```typescript
import { setDebug } from '@twa.js/bridge';
import { setDebug } from '@tma.js/bridge';

setDebug(true);
```
Expand All @@ -115,7 +115,7 @@ setDebug(true);
If the package is being used in a browser environment (iframe), we employ the function `window.parent.postMessage`. This function requires specifying the target origin to ensure events are only sent to trusted parent iframes. By default, the package utilizes `https://web.telegram.org` as the origin. To enable event transmission to other origins, you should utilize the `setTargetOrigin` function:

```typescript
import { setTargetOrigin } from '@twa.js/bridge';
import { setTargetOrigin } from '@tma.js/bridge';

setTargetOrigin('https://myendpoint.org');
```
Expand All @@ -128,4 +128,4 @@ It is strongly recommended not to override this value as long as it could lead t

## Higher-level control

As long as the package provides only low-level control, we recommend using [SDK](./twa-js-sdk/about.mdx) which implements package methods. It also provides additional some automatic parameters checks, more intuitive method names, and easier usage.
As long as the package provides only low-level control, we recommend using [SDK](./tma-js-sdk/about.mdx) which implements package methods. It also provides additional some automatic parameters checks, more intuitive method names, and easier usage.
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
---
sidebar_label: "@twa.js/init-data-node"
sidebar_label: "@tma.js/init-data-node"
sidebar_position: 3
---

# @twa.js/init-data-node
# @tma.js/init-data-node

<LibraryBadges pkg={'@twa.js/init-data-node'}/>
<LibraryBadges pkg={'@tma.js/init-data-node'}/>

The package provides utilities to work with the initialization data of Telegram Web Apps on the server side. To learn more about the initialization data and its usage, please refer to the [documentation](../launch-params/init-data.mdx).
The package provides utilities to work with the initialization data of Telegram Mini Apps on the server side. To learn more about the initialization data and its usage, please refer to the [documentation](../launch-params/init-data.mdx).

:::note

This package extends the functionality of [`@twa.js/init-data`](twa-js-init-data), including all its types and utilities. Therefore, there is no need to install both packages separately.
This package extends the functionality of [`@tma.js/init-data`](tma-js-init-data), including all its types and utilities. Therefore, there is no need to install both packages separately.

:::

## Installation

<NpmInstall pkg={'@twa.js/init-data-node'}/>
<NpmInstall pkg={'@tma.js/init-data-node'}/>

## Usage

### Parsing

You can learn more about parsing utilities in [`@twa.js/init-data`](twa-js-init-data#parsing) documentation.
You can learn more about parsing utilities in [`@tma.js/init-data`](tma-js-init-data#parsing) documentation.

### Validation

To validate the signature of the initialization data, the `validate` function is used. It expects the initialization data to be passed in raw format (search parameters) and throws an error in certain cases.

```typescript
import { validate } from '@twa.js/init-data-node';
import { validate } from '@tma.js/init-data-node';

const secretToken = '5768337691:AAH5YkoiEuPk8-FZa32hStHTqXiLPtAEhx8';
const initData =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
sidebar_label: "@twa.js/init-data"
sidebar_label: "@tma.js/init-data"
sidebar_position: 2
---

# @twa.js/init-data
# @tma.js/init-data

<LibraryBadges pkg={'@twa.js/init-data'}/>
<LibraryBadges pkg={'@tma.js/init-data'}/>

The package provides utilities to work with the initialization data of Telegram Web Apps on the client side. To learn more about the initialization data and its usage, please refer to the [documentation](../launch-params/init-data.mdx).
The package provides utilities to work with the initialization data of Telegram Mini Apps on the client side. To learn more about the initialization data and its usage, please refer to the [documentation](../launch-params/init-data.mdx).

## Installation

<NpmInstall pkg={'@twa.js/init-data'}/>
<NpmInstall pkg={'@tma.js/init-data'}/>

## Usage

Expand All @@ -20,7 +20,7 @@ The package provides utilities to work with the initialization data of Telegram
This library includes the function `initData`, which can extract initialization data information from query parameters. Here is an example of its usage:

```typescript
import { initData } from '@twa.js/init-data';
import { initData } from '@tma.js/init-data';

// Let's imagine, we have init data in a raw format like this. Web Apps are
// sending it in the exact same format.
Expand Down Expand Up @@ -55,4 +55,4 @@ The function extracts the required parameters and automatically validates their

### Validation

We have moved the validation utilities to a separate [TypeScript package](twa-js-init-data-node.mdx). These utilities are only needed on the server side, as there is no need to validate initialization data on the client side.
We have moved the validation utilities to a separate [TypeScript package](tma-js-init-data-node.mdx). These utilities are only needed on the server side, as there is no need to validate initialization data on the client side.
Loading

0 comments on commit a0ab76f

Please sign in to comment.