Skip to content

Commit

Permalink
Merge pull request #4 from micromagicman/develop
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
micromagicman committed Nov 21, 2023
2 parents c255367 + a76f931 commit 3b2d7cd
Show file tree
Hide file tree
Showing 27 changed files with 9,280 additions and 31 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/laravel-telegram-webapp-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: laravel-telegram-webapp

on:
push:
branches: [ "develop", "master" ]
pull_request:
branches: [ "develop", "master" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: run tests
uses: php-actions/phpunit@v3
env:
XDEBUG_MODE: coverage
with:
configuration: phpunit.xml
php_extensions: xdebug
args: tests --coverage-clover ./coverage.xml
- name: upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/.idea/
/vendor/
/vendor/
/.phpunit.cache/

TODO.txt
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright 2023, Micromagicman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Laravel Telegram WebApp package

![build](https://github.com/micromagicman/laravel-telegram-webapp/actions/workflows/laravel-telegram-webapp-ci.yml/badge.svg)
[![codecov](https://codecov.io/github/micromagicman/laravel-telegram-webapp/graph/badge.svg?token=ZSVF7MGB38)](https://codecov.io/github/micromagicman/laravel-telegram-webapp)

Laravel package that allows you to process commands from Telegram MiniApp with user verification according to
[Telegram MiniApp developer documentation](https://core.telegram.org/bots/webapps), as well as obtaining information
about the Telegram user who sent the request

## Install

### Via composer

```bash
composer require micromagicman/laravel-telegram-webapp
```

### Publishing

Publish to your Laravel application:

```bash
php artisan vendor:publish --provider="Micromagicman\TelegramWebApp\TelegramWebAppServiceProvider"
```

## Configure

All package configuration available in `config/telegram-webapp.php` file after `publish` command execution:

| Config name | Description | Environment | Default value |
|------------------------|------------------------------------------------------------------------------|-------------------------------------------|-----------------------------------------------|
| `enabled` | Telegram MiniApp data validation switch | `TELEGRAM_WEBAPP_DATA_VALIDATION_ENABLED` | `true` |
| `webAppScriptLocation` | Path to script (.js) which initializes Telegram MiniApp on your frontend app | - | `https://telegram.org/js/telegram-web-app.js` |
| `botToken` | Your Telegram bot token | `TELEGRAM_BOT_TOKEN` | - |
| `error.status` | HTTP status code when Telegram MiniApp data validation fails | - | 403 (Forbidden) |
| `error.message` | HTTP status code when Telegram MiniApp data validation fails | - | 403 (Forbidden) |

Example in code:

## View

This package provides a root view for Telegram MiniApp frontend applications.
[Telegram WebApp script](https://telegram.org/js/telegram-web-app.js) is automatically includes to this view or its
inheritors if `telegram-webapp.enabled` switch is `true`

Example:

```php
@extends('telegram-webapp::main')

@section('lang', 'CN')

@section('head')
// some scripts, css, meta
@endsection

@section('title', 'My title')

@section('content')
<div id="app-content">
// My spa content
</div>
@endsection
```
84 changes: 62 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,65 @@
{
"name": "micromagicman/laravel-telegram-webapp",
"description": "Laravel middleware for Telegram WebApp data validation",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"Micromagicman\\TelegramWebApp\\": "src/"
"name": "micromagicman/laravel-telegram-webapp",
"description": "Laravel middleware for Telegram WebApp data validation",
"type": "library",
"license": "MIT",
"keywords": ["telegram", "miniapp", "bot", "laravel"],
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Micromagicman\\TelegramWebApp\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Micromagicman\\TelegramWebApp\\Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"authors": [
{
"name": "micromagicman",
"email": "evgen@micromagicman.ru"
}
],
"require": {
"php": ">=8.1",
"illuminate/support": "^10.28",
"illuminate/routing": "^10.28"
},
"require-dev": {
"ext-dom": "*",
"phpunit/phpunit": "^10.4",
"orchestra/testbench": "^8.14",
"nunomaduro/collision": "^7.8",
"phpunit/php-code-coverage": "^10.1"
},
"extra": {
"laravel": {
"providers": [
"Micromagicman\\TelegramWebApp\\TelegramWebAppServiceProvider"
],
"aliases": {
"TelegramWebApp": "Micromagicman\\TelegramWebApp\\Facade\\TelegramFacade"
}
}
},
"scripts": {
"test": "./vendor/bin/phpunit",
"post-autoload-dump": [
"@clear",
"@prepare"
],
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"@build",
"@php vendor/bin/testbench serve"
]
}
},
"authors": [
{
"name": "micromagicman",
"email": "evgen@micromagicman.ru"
}
],
"require": {},
"extra": {
"laravel": {
"providers": [
"Micromagicman\\TelegramWebApp\\WebAppDataValidationProvider"
]
}
}
}
Loading

0 comments on commit 3b2d7cd

Please sign in to comment.