Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirHkrg committed Jul 10, 2023
1 parent 244c6fb commit 5eceabb
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ API_HASH=
SERVER_IP=127.0.0.1
SERVER_PORT=9000

# LOG (not available yet) :
# LOG ( not available yet ) :
LOG=off
LOG_FOLDER=

Expand Down
279 changes: 150 additions & 129 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ LaraGram, an advanced framework for Telegram Bot development
- MySql
- Redis
- Json
-

---

# Installation

Expand All @@ -29,94 +32,66 @@ composer create-project laraxgram/laragram:dev-master@dev my-bot

# Get Start ...

### Terminal Command :

###### make and remove resource

```
php bot make:resource my-resource
php bot remove:resource my-resource
```

###### model and migration

```
php bot make:model User
php bot make:migration create_users_table
```

###### Server

* start Web server

If you are working on a local host, it is better to use this web server
Otherwise, Apache, Nginx, etc. web servers are a better option
```
php bot serve
```

* start Web server and Bot Api Server

```
php bot serve --api-server
```

* start Bot OpenSwoole Server

```
php bot serve --openswoole
```
Or
```
php bot start:openswoole
```
* Start Openswoole server and bot api server
```
php bot serve --openswoole --api-server
```
### Usage:

* start Bot Api Server
1. make a resource and open it
2. Create an instance of Bot()

```php
$bot = new Bot();
```
php bot start:apiserver
```

###### Webhook

* manage Webhook

```
php bot setWebhook
3. Start Coding

php bot deleteWebhook
```php
$bot->onText('hello', function(Request $request){
$request->sendMessage([
'chat_id' => $request->ChatID(),
'text' => 'hi'
]);
});
```

###### Manage Dependency

* Database Eloquent

```
php bot get:eloqunet
* Use Variable

php bot remove:eloqunet
```php
$bot->onText('say {text}', function(Request $request, $text){
$request->sendMessage([
'chat_id' => $request->ChatID(),
'text' => $text
]);
});
```

* AMPHP
* Pass Multiple Pattern

```php
$bot->onText(['hello', 'hay'], function(Request $request){
$request->sendMessage([
'chat_id' => $request->ChatID(),
'text' => 'hi'
]);
});
```
php bot get:amphp

php bot remove:amphp
```
* Change Request Mode

* OpenSwoole
##### Constant

```
php bot get:openswoole
| Type | Name | Int |
|----------------------------------|---------------------------------|-------|
| Curl (Default) | `REQUEST_METHODE_CURL` | `32` |
| Parallel curl | `REQUEST_METHODE_PARALLEL_CURL` | `64` |
| AMPHP | `REQUEST_METHODE_AMPHP` | `128` |
| OpenSwoole ( Not available yet ) | `REQUEST_METHODE_OPENSWOOLE` | `256` |

php bot remove:openswoole
```php
$bot->onText(['hello', 'hay'], function(Request $request){
$request->sendMessage([
'chat_id' => $request->ChatID(),
'text' => 'hi'
], REQUEST_METHODE_PARALLEL_CURL);
});
```

---
Expand Down Expand Up @@ -168,94 +143,140 @@ php bot remove:openswoole

---

### Usage:
### Use Redis :

1. make a resource and open it
2. Create an instance of Bot()
* Simple Use :

```php
$bot = new Bot();
// init Redis Server
$redis = PhpRedis::connect();

// set
$redis->set('foo', 'bar');

//get
$data = $redis->get('foo'));
echo $data;
// Result : bar
```

3. Start Coding
* Pass Db name:

```php
$bot->onText('hello', function(Request $request){
$request->sendMessage([
'chat_id' => $request->ChatID(),
'text' => 'hi'
]);
});
// init Redis Server with db name
$redis = PhpRedis::connect('dbname');
```

* Use Variable
---

### Terminal Command :

###### make and remove resource

```php
$bot->onText('say {text}', function(Request $request, $text){
$request->sendMessage([
'chat_id' => $request->ChatID(),
'text' => $text
]);
});
```
php bot make:resource my-resource
* Pass Multiple Pattern
php bot remove:resource my-resource
```

###### model and migration

```php
$bot->onText(['hello', 'hay'], function(Request $request){
$request->sendMessage([
'chat_id' => $request->ChatID(),
'text' => 'hi'
]);
});
```
php bot make:model User
* Change Request Mode
php bot make:migration create_users_table
```

##### Constant
| Type | Name | Int |
|---------------|------|-----|
| Curl (defult) | `REQUEST_METHODE_CURL` | `32` |
| Parallel curl | `REQUEST_METHODE_PARALLEL_CURL` | `64` |
| AMPHP | `REQUEST_METHODE_AMPHP` | `128` |
| OpenSwoole | `REQUEST_METHODE_OPENSWOOLE` | `256` |
###### Server

* start Web server

```php
$bot->onText(['hello', 'hay'], function(Request $request){
$request->sendMessage([
'chat_id' => $request->ChatID(),
'text' => 'hi'
], REQUEST_METHODE_PARALLEL_CURL);
});
If you are working on a local host, it is better to use this web server
Otherwise, Apache, Nginx, etc. web servers are a better option ( For `php bot serve` command only )

```
php bot serve
```

### Use Redis :
* start Web server and Bot Api Server

* Simple Use :
```
php bot serve --api-server
```

```php
// init Redis Server
$redis = PhpRedis::connect();
* start Bot OpenSwoole Server

// set
$redis->set('foo', 'bar');
```
php bot serve --openswoole
```

//get
$data = $redis->get('foo'));
echo $data;
// Result : var
Or

```
php bot start:openswoole
```

* Pass Db name:
```php
// init Redis Server with db name
$redis = PhpRedis::connect('dbname');
* Start Openswoole server and bot api server

```
php bot serve --openswoole --api-server
```

* start Bot Api Server

```
php bot start:apiserver
```

###### Webhook

* manage Webhook

```
php bot setWebhook
php bot deleteWebhook
```

###### Manage Dependency

* Database Eloquent

```
php bot get:eloqunet
php bot remove:eloqunet
```

* AMPHP

```
php bot get:amphp
php bot remove:amphp
```

* OpenSwoole

```
php bot get:openswoole
php bot remove:openswoole
```

* Clean Vendor

Remove all extra dependencies

```
php bot clear:vendor
```

# Support & Contact:

* [Email](mailto:amirh.kargar895@gmail.com)
* [Telegram](https://telegram.me/Amirh_krgr)

# Updating ...

###### Version 1.4
6 changes: 3 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
Versions currently supported with security updates.

| Version | Supported |
|---------| ------------------ |
| 1.0.x | :x: |
| 1.1.x | :x: |
|---------|--------------------|
| 1.0.x | :x: |
| 1.1.x | :x: |
| 1.2.x | :white_check_mark: |
| 1.3.x | :white_check_mark: |
| 1.4.x | :white_check_mark: |
Expand Down
8 changes: 7 additions & 1 deletion bootstrap/runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

namespace Bot\Bootstrap;

use Bot\Core\Connect\Openswoole;

class Runner
{
public static function start(): void
{
$files = json_decode(file_get_contents('bootstrap/load.json'), true);
foreach ($files as $file) {
require $file;
if (!isset(Openswoole::$openswoole)){
require_once $file;
}else{
require $file;
}
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"ext-curl": "*",
"ext-redis": "*"
}
}
}
Loading

0 comments on commit 5eceabb

Please sign in to comment.