npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

walnut-web-app

v6.4.0

Published

Bring your WebApp into effect outside of Telegram WebView

Downloads

226

Readme

build npm cdnjs minified size license

walnut-web-app

Bring your WebApp into effect outside of Telegram WebView.

Table of Contents

General Information

This package achieves something otherwise impossible by intervening between WebView and WebApp. It makes the testing process significantly smoother.

Schematic

I would greatly appreciate it if you could create a drawing for me, especially if it's done with more skill.

Setup

$ npm i -D walnut-web-app

Usage

To ensure proper operation, walnut-web-app must be imported before Telegram. This is because it alters the location.hash to enable the WebApp to function outside of Telegram WebView.

// destructured import
import { utils, event } from 'walnut-web-app'
// import all exported members
import * as walnut from 'walnut-web-app'
// import default export
import walnut from 'walnut-web-app'

Here are two options for using walnut-web-app:

  1. Simply import the package without any additional configurations (utilizing the default settings):
// main.js
import 'walnut-web-app'
import 'miku-web-app' // import Telegram
import router from '@/router'
import App from './App.vue'
  1. Import the package and make custom configurations:
// main.js
import '@/walnut'
import 'miku-web-app' // import Telegram
import router from '@/router'
import App from './App.vue'
// src/walnut/index.js
import walnut from 'walnut-web-app'

// default settings
walnut.utils.setup({
  Data: {
    user: {
      id: 127355800,
      first_name: '初音',
      last_name: 'ミク',
      username: 'miku3920',
      language_code: 'zh-hant',
    },
    auth_date: Date.now(),
    token: '1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  },
  Version: '6.4',
  Platform: 'tdesktop',
  ThemeParams: {
    bg_color: '#ffffff',
    button_color: '#40a7e3',
    button_text_color: '#ffffff',
    hint_color: '#999999',
    link_color: '#168acd',
    text_color: '#000000',
  },
  Debug: true,
})

walnut.event.on('default', (e) => {
  console.log('[Walnut.default] postEvent', e.type, e.data)
})

walnut.event.on('all', (e) => {
  // do no things
})

Configuration

Customize settings as desired: If you don't specify any settings, the default values will be used.

setup

This technique allows you to lock in a specific time:

walnut.utils.setup({
  Data: {
    auth_date: 1658213143920,
  }
})

| Field | Type | Description | | ----------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Data | SetupData | Optional. This object contains data that is transferred to the Web App when it is opened. | | Version | String | Optional. The version of the Bot API available in the user's Telegram app. Set to 6.4 by default. | | Platform | String | Optional. The name of the platform of the user's Telegram app. Set to tdesktop by default. | | ThemeParams | ThemeParams | Optional. Web Apps can adjust the appearance of the interface to match the Telegram user's app in real time. This object contains the user's current theme settings. | | Debug | Boolean | Optional. Make the MainButton visible outside of Telegram WebView. Set to true by default. |

SetupData

| Field | Type | Description | | -------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | query_id | string | Optional. A fake unique identifier for the Web App session. Messages cannot be sent via the answerWebAppQuery method. | | user | WebAppUser | Optional. An object containing data about the current user. | | receiver | WebAppUser | Optional. An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu. | | chat | WebAppChat | Optional. An object containing data about the chat where the bot was launched via the attachment menu. | | start_param | string | Optional. The value of the startattach parameter, passed via link. | | can_send_after | number | Optional. Fake time in seconds. Message cannot be sent via the answerWebAppQuery method for any length of time. | | auth_date | number | Optional. Unix time when the form was opened. | | token | string | Optional. Any token that is the same as you use for server-side validation |

event

If no event handler is set, the default event handler will be used to handle all events. The all event handler, on the other hand, will handle all events, regardless of the specific event handler being set or not.

If you want to trigger the original event, use the e.post() method:

walnut.event.on('all', (e) => {
  e.post()
})

// e.post inside of Telegram WebView
TelegramWebviewProxy.postEvent(e.type, e.data)

// e.post outside of Telegram WebView
console.log('[Walnut.debug] postEvent', e.type, e.data)

| eventType | | ---------------------------------- | | default | | all | | web_app_setup_closing_behavior | | web_app_set_header_color | | web_app_set_background_color | | web_app_setup_back_button | | web_app_setup_main_button | | web_app_trigger_haptic_feedback | | web_app_data_send | | web_app_open_link | | web_app_open_tg_link | | web_app_open_invoice | | web_app_open_popup | | web_app_open_scan_qr_popup | | web_app_close_scan_qr_popup | | web_app_read_text_from_clipboard | | web_app_ready | | web_app_expand | | web_app_close | | web_app_request_theme | | web_app_request_viewport |

Contact

Created by @miku3920. Feel free to contact me if you have any questions or run into any issues!