Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/roziscoding/grammy-vue


https://github.com/roziscoding/grammy-vue

Last synced: about 18 hours ago
JSON representation

Awesome Lists containing this project

README

        

grammy-vue
---

Simple utility hook to call the Telegram API using [grammy](https://grammy.dev) and track the request status with Vue.js refs

## Usage

```html

import { ref } from 'vue';
import { useTelegramApi } from 'grammy-vue';

const token = ref('')
const { useApiMethod } = useTelegramApi(token)
const { refresh: getMe, state, data: botInfo, error } = useApiMethod('getMe')


GetMe

Type the token and click the button

Loading bot info...

Grammy error: {{ error.message }}

Loaded info for bot {{ botInfo.username }}

```

### Resetting status after a set amount of time

The `useApiMethod` hook takes an optional second parameter, which is the number of milliseconds to wait before setting the state back to `idle`. If you don't specify this parameter, the state will not be automatically reset.

```html

import { ref } from 'vue';
import { useTelegramApi } from 'grammy-vue';

const token = ref('')
const url = ref('')
const { useApiMethod } = useTelegramApi(token)
const { refresh: setWebhook, state, error } = useApiMethod('setWebhook', 1000) // state will be reset after 1 second



SetWebhook

Type the token and the url, then click the button

Setting webhook...

Grammy error: {{ error.message }}

Webhook was set!

```