Skip to content

Commit 01827a5

Browse files
committed
Added tests
1 parent 9bc25ee commit 01827a5

23 files changed

+2453
-127
lines changed

.travis.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- 7.0
9+
- hhvm
10+
11+
sudo: false
12+
13+
before_install:
14+
- composer self-update
15+
16+
install:
17+
- travis_retry composer install --no-interaction --prefer-source
18+
19+
script:
20+
- phpunit
21+
- sh -c "if [ '$TRAVIS_PHP_VERSION' != '7.0' ]; then vendor/bin/phpcs --report=full --extensions=php -p --standard=build/phpcs .; fi"
22+
23+
matrix:
24+
allow_failures:
25+
- php: hhvm
26+
- php: 7.0
27+
fast_finish: true
28+
29+
30+
notifications:
31+
on_success: never
32+
on_failure: always

README.md

+28-10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Instructions
5959
## Installation
6060
You need server with https and composer support.
6161

62+
Install this package through [Composer](https://getcomposer.org/). Edit your project's `composer.json` file to require `longman/telegram-bot`.
63+
6264
Create composer.json file:
6365
```js
6466
{
@@ -70,9 +72,13 @@ Create composer.json file:
7072
}
7173
}
7274
```
73-
7475
And run composer update
7576

77+
**Or** run a command in your command line:
78+
79+
```
80+
composer require longman/telegram-bot
81+
```
7682

7783
###### bot token
7884
You will notice that the Telegram Bot wants a value for `API_KEY`. This token may be obtained via a telegram client for your bot. See [this](https://core.telegram.org/bots#botfather) link if you are unsure of how to so this.
@@ -90,13 +96,19 @@ $loader = require __DIR__.'/vendor/autoload.php';
9096
$API_KEY = 'your_bot_api_key';
9197
$BOT_NAME = 'namebot';
9298

93-
// create Telegram API object
94-
$telegram = new Longman\TelegramBot\Telegram($API_KEY,$BOT_NAME);
95-
96-
// set webhook
97-
echo $telegram->setWebHook('https://yourdomain/yourpath_to_hook.php');
99+
try {
100+
// create Telegram API object
101+
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
98102

103+
// set webhook
104+
echo $telegram->setWebHook('https://yourdomain/yourpath_to_hook.php');
105+
}
106+
catch (Longman\TelegramBot\Exception\TelegramException $e) {
107+
echo $e->getMessage();
108+
}
99109
```
110+
And open your set.php via browser
111+
100112

101113
After create hook.php and put:
102114
```php
@@ -106,12 +118,18 @@ $loader = require __DIR__.'/vendor/autoload.php';
106118

107119
$API_KEY = 'your_bot_api_key';
108120
$BOT_NAME = 'namebot';
109-
// create Telegram API object
110-
$telegram = new Longman\TelegramBot\Telegram($API_KEY,$BOT_NAME);
111121

112-
// handle telegram webhook request
113-
$telegram->handle();
122+
try {
123+
// create Telegram API object
124+
$telegram = new Longman\TelegramBot\Telegram($API_KEY,$BOT_NAME);
114125

126+
// handle telegram webhook request
127+
$telegram->handle();
128+
}
129+
catch (Longman\TelegramBot\Exception\TelegramException $e) {
130+
// log telegram errors
131+
// echo $e->getMessage();
132+
}
115133
```
116134

117135
If you want insert in database messages for further usage in commands, create database and import structure.sql and enable mysql support after object creation and BEFORE handle method

composer.json

+40-41
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
{
2-
"name": "longman/telegram-bot",
3-
"type": "library",
4-
"description": "PHP telegram bot",
5-
"keywords": ["telegram", "bot", "api"],
6-
"license": "MIT",
7-
"homepage": "https://github.com/akalongman/php-telegram-bot",
8-
"support": {
9-
"issues": "https://github.com/akalongman/php-telegram-bot/issues",
10-
"source": "https://github.com/akalongman/php-telegram-bot"
11-
},
12-
"authors": [
13-
{
14-
"name": "Avtandil Kikabidze aka LONGMAN",
15-
"email": "[email protected]",
16-
"homepage": "http://longman.ge",
17-
"role": "Developer"
18-
}
19-
],
20-
"require": {
21-
"php": ">=5.3.0",
22-
"ext-pdo": "*",
23-
"hoa/math":"~0.0"
24-
25-
},
26-
"autoload": {
27-
"psr-4": {
28-
"Longman\\TelegramBot\\": "src/"
29-
}
30-
},
31-
"autoload-dev": {
32-
"psr-4": {
33-
"Tests\\": "tests/"
34-
}
35-
},
36-
"minimum-stability": "dev",
37-
"require-dev": {
38-
"phpunit/phpunit": "4.1.*",
39-
"phpspec/phpspec": "~2.1",
40-
"squizlabs/php_codesniffer": "2.3.*"
41-
}
42-
}
2+
"name": "longman/telegram-bot",
3+
"type": "library",
4+
"description": "PHP telegram bot",
5+
"keywords": ["telegram", "bot", "api"],
6+
"license": "MIT",
7+
"homepage": "https://github.com/akalongman/php-telegram-bot",
8+
"support": {
9+
"issues": "https://github.com/akalongman/php-telegram-bot/issues",
10+
"source": "https://github.com/akalongman/php-telegram-bot"
11+
},
12+
"authors": [
13+
{
14+
"name": "Avtandil Kikabidze aka LONGMAN",
15+
"email": "[email protected]",
16+
"homepage": "http://longman.ge",
17+
"role": "Developer"
18+
}
19+
],
20+
"require": {
21+
"php": ">=5.3.0",
22+
"ext-pdo": "*",
23+
"hoa/math": "~0.0"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"Longman\\TelegramBot\\": "src/"
28+
}
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"Tests\\": "tests/"
33+
}
34+
},
35+
"minimum-stability": "dev",
36+
"require-dev": {
37+
"phpunit/phpunit": "4.1.*",
38+
"phpspec/phpspec": "~2.1",
39+
"squizlabs/php_codesniffer": "2.3.*"
40+
}
41+
}

0 commit comments

Comments
 (0)