markdown Laravel出席
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Laravel出席相关的知识,希望对你有一定的参考价值。
# Create Telegram Bot
1. Find BotFather
2. Create New Bot
3. Register Bot Commands to be Use
- [x] start - Start to use Bot Demo
- [x] checkin - Check In
- [x] checkout - Check Out
- [x] register - Register Employee
- [x] unregister - Unregister Employee
- [x] help - Show help
# Initial Setup
**Installation of Telegram Bot Package**
```
$ composer require irazasyed/telegram-bot-sdk ^2.0
```
**Add Service Provider in `config/app.php`**
```php
Telegram\Bot\Laravel\TelegramServiceProvider::class
```
**Add Facade in `config/app.php`**
```php
'Telegram' => Telegram\Bot\Laravel\Facades\Telegram::class
```
**Publish Configuration File**
```bash
$ php artisan vendor:publish --provider="Telegram\Bot\Laravel\TelegramServiceProvider"
```
**Define Telegram Bot Token**
Go to BotFather, create and generate the Telegram Bot. Then get the token.
Once you have it, add in `.env` file key - `TELEGRAM_BOT_TOKEN="YOUR-BOT-TOKEN-HERE"`.
Then in console, run `php artisan config:cache`.
# Test Setup
Copy paste the following codes in `routes/console.php`
```php
<?php
Artisan::command('telegram:me', function () {
$this->info('Getting information about you...');
$response = Telegram::getMe();
$this->info('Your name is ' . $response->getFirstName());
})->describe('Telegram - About Me');
```
And run `php artisan telegram:me` in console.
# Telegram Webhook
1. Create a file named `routes/webhook.php`.
2. Go to `app/Providers/RouteServiceProvider.php`, add the following:
```php
/**
* Define the "webhook" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapWebHookRoutes()
{
Route::prefix('webhook')
->namespace($this->namespace)
->group(base_path('routes/webhook.php'));
}
```
3. And add the following in `map()` method in `app/Providers/RouteServiceProvider.php`
```php
$this->mapWebHookRoutes();
```
4. Once you're done, add the following in `routes/webhook.php`
```php
<?php
Route::post('/attendance/telegram/' . config('telegram.bot_token'), function () {
$updates = Telegram::getWebhookUpdates();
logger()->info($updates);
})->name('attendance.telegram.webhook');
```
Now should have a working webhook, but you need a live server to make this working.
For MacOS user, you can use `valet share`. Other platform, you may download and use ngrok.io.
# Set Webhook to Telegram
I've made a simple Artisan command to set and unset Telegram webhook we added above.
Just copy and paste the following codes in `routes/console.php`:
```php
Artisan::command('telegram:setHook {domain?}', function () {
$url = ($this->argument('domain') ?? config('app.url')) . '/webhook/attendance/telegram/' . config('telegram.bot_token');
$response = Telegram::setWebhook(['url' => $url]);
if ($response) {
$this->info('Telegram Webhook successfully created.');
} else {
$this->error('Unable to set Telegram Webhook');
}
})->describe('Telegram - Set Web Hook');
Artisan::command('telegram:unsetHook {domain?}', function () {
$url = ($this->argument('domain') ?? config('app.url')) . '/webhook/attendance/telegram/' . config('telegram.bot_token');
$response = Telegram::removeWebhook(['url' => $url]);
if ($response) {
$this->info('Telegram Webhook successfully removed.');
} else {
$this->error('Unable to unset Telegram Webhook');
}
})->describe('Telegram - Set Web Hook');
```
You just need to run `php artisan telegram:setHook <your-domain-name>`, then you're done setting up your application with Telegram.
# Create Command
-- IGNORE BELOW ---
Prepare a list of commands we need to use:
1. **/start** - `php artisan make:command Attendance/Telegram/StartCommand`
2. **/checkin** - `php artisan make:command Attendance/Telegram/CheckInCommand`
3. **/checkout** - `php artisan make:command Attendance/Telegram/CheckOutCommand`
Next, you must use the SDK Telegram Command classes - refer [Commands System](https://telegram-bot-sdk.readme.io/docs/commands-system)
Once you're done with your logic, do register the commands in `config/telegram.php` on `commands` key.
Now you're ready with Laravel Attendance with Telegram.
p/s: you just need to implement how to store
以上是关于markdown Laravel出席的主要内容,如果未能解决你的问题,请参考以下文章
Laravel 可以验证 markdown mime 类型吗?
Laravel5.1 搭建简单的社区--引入MarkDown