Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
61481e19
Commit
61481e19
authored
Feb 11, 2016
by
Marco Boretto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #99 from noplanman/correct_readme_and_examples
Correct readme and examples
parents
f11c153c
a6d527f2
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
268 additions
and
206 deletions
+268
-206
README.md
README.md
+189
-128
getUpdatesCLI.php
examples/getUpdatesCLI.php
+32
-33
hook.php
examples/hook.php
+30
-30
set.php
examples/set.php
+11
-9
unset.php
examples/unset.php
+6
-6
No files found.
README.md
View file @
61481e19
This diff is collapsed.
Click to expand it.
examples/getUpdatesCLI.php
View file @
61481e19
...
...
@@ -7,60 +7,59 @@
#bash script
#while true; do ./getUpdatesCLI.php; done
//Composer Loader
$dir
=
realpath
(
__DIR__
.
'/..'
);
$loader
=
require
$dir
.
'/vendor/autoload.php'
;
// Load composer
require
__DIR__
.
'/vendor/autoload.php'
;
$API_KEY
=
'your_bot_api_key'
;
$BOT_NAME
=
'namebot'
;
//$
COMMANDS_FOLDER = __DIR__.
'/Commands/';
$credentials
=
[
'host'
=>
'localhost'
,
'user'
=>
'dbuser'
,
'password'
=>
'dbpass'
,
'database'
=>
'dbname'
//$
commands_path = __DIR__ .
'/Commands/';
$
mysql_
credentials
=
[
'host'
=>
'localhost'
,
'user'
=>
'dbuser'
,
'password'
=>
'dbpass'
,
'database'
=>
'dbname'
,
];
try
{
//
c
reate Telegram API object
//
C
reate Telegram API object
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_NAME
);
//
//Options
$telegram
->
enableMySQL
(
$credentials
);
//
Enable MySQL
$telegram
->
enableMySQL
(
$
mysql_
credentials
);
////
Enable mysql
with table prefix
//$telegram->enableMySQL($
credentials, $BOT_NAME.
'_');
////
Enable MySQL
with table prefix
//$telegram->enableMySQL($
mysql_credentials, $BOT_NAME .
'_');
//$telegram->addCommandsPath($COMMANDS_FOLDER);
//// Add an additional commands path
//$telegram->addCommandsPath($commands_path);
////
Here you can enable admin interface ache
the channel you want to manage
////
Here you can enable admin interface for
the channel you want to manage
//$telegram->enableAdmins(['your_telegram_id']);
//$telegram->setCommandConfig('sendtochannel', ['your_channel'
=>
'@type_here_your_channel']);
//$telegram->setCommandConfig('sendtochannel', ['your_channel'
=>
'@type_here_your_channel']);
////
Here you can set some command specified
parameters,
////for example, google geocode/timezone api key for date command:
//$telegram->setCommandConfig('date',
array('google_api_key'=>'your_google_api_key_here')
);
////
Here you can set some command specific
parameters,
////
for example, google geocode/timezone api key for date command:
//$telegram->setCommandConfig('date',
['google_api_key' => 'your_google_api_key_here']
);
////Logging
////
Logging
//$telegram->setLogRequests(true);
//$telegram->setLogPath($BOT_NAME
.
'.log');
//$telegram->setLogPath($BOT_NAME
.
'.log');
//$telegram->setLogVerbosity(3);
//$telegram->setDownloadPath("../Download");
//$telegram->setUploadPath("../Upload");
//// Set custom Upload and Download path
//$telegram->setDownloadPath('../Download');
//$telegram->setUploadPath('../Upload');
//
h
andle telegram getUpdate request
//
H
andle telegram getUpdate request
$ServerResponse
=
$telegram
->
handleGetUpdates
();
if
(
$ServerResponse
->
isOk
())
{
$n_update
=
count
(
$ServerResponse
->
getResult
());
print
(
date
(
'Y-m-d H:i:s'
,
time
())
.
' - Processed '
.
$n_update
.
" updates
\n
"
);
print
(
date
(
'Y-m-d H:i:s'
,
time
())
.
' - Processed '
.
$n_update
.
' updates'
.
"
\n
"
);
}
else
{
print
(
date
(
'Y-m-d H:i:s'
,
time
())
.
" - Fail fetch updates
\n
"
);
echo
$ServerResponse
->
printError
()
.
"
\n
"
;
print
(
date
(
'Y-m-d H:i:s'
,
time
())
.
' - Failed to fetch updates'
.
"
\n
"
);
echo
$ServerResponse
->
printError
()
.
"
\n
"
;
}
}
catch
(
Longman\TelegramBot\Exception\TelegramException
$e
)
{
// log telegram errors
echo
$e
;
...
...
examples/hook.php
View file @
61481e19
<?php
//README
//This configuration file is inten
t
ed to run the bot with the webhook method.
//This configuration file is inten
d
ed to run the bot with the webhook method.
//Uncommented parameters must be filled
//Please notice that if you open this file with your browser you'll get the "Input is empty!" Exception.
//This is a normal behaviour because this address has to be reached only by Telegram server
//Composer Loader
$dir
=
realpath
(
__DIR__
.
'/..'
);
$loader
=
require
$dir
.
'/vendor/autoload.php'
;
// Load composer
require
__DIR__
.
'/vendor/autoload.php'
;
$API_KEY
=
'your_bot_api_key'
;
$BOT_NAME
=
'namebot'
;
//$
COMMANDS_FOLDER = __DIR__.
'/Commands/';
//$credentials = [
// 'host'
=>
'localhost',
// 'user'
=>
'dbuser',
// 'password'
=>
'dbpass',
// 'database'
=>'dbname'
//$
commands_path = __DIR__ .
'/Commands/';
//$
mysql_
credentials = [
// 'host'
=>
'localhost',
// 'user'
=>
'dbuser',
// 'password'
=>
'dbpass',
// 'database'
=> 'dbname',
//];
try
{
//
c
reate Telegram API object
//
C
reate Telegram API object
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_NAME
);
////
Options
$telegram
->
enableMySQL
(
$
credentials
);
////
Enable MySQL
//$telegram->enableMySQL($mysql_
credentials);
////
Enable mysql
with table prefix
//$telegram->enableMySQL($
credentials, $BOT_NAME.
'_');
////
Enable MySQL
with table prefix
//$telegram->enableMySQL($
mysql_credentials, $BOT_NAME .
'_');
//$telegram->addCommandsPath($COMMANDS_FOLDER);
//// Add an additional commands path
//$telegram->addCommandsPath($commands_path);
////
Here you can enable admin interface ache
the channel you want to manage
////
Here you can enable admin interface for
the channel you want to manage
//$telegram->enableAdmins(['your_telegram_id']);
//$telegram->setCommandConfig('sendtochannel', ['your_channel'
=>
'@type_here_your_channel']);
//$telegram->setCommandConfig('sendtochannel', ['your_channel'
=>
'@type_here_your_channel']);
////
Here you can set some command specified
parameters,
////for example, google geocode/timezone api key for date command:
//$telegram->setCommandConfig('date',
array('google_api_key'=>'your_google_api_key_here')
);
////
Here you can set some command specific
parameters,
////
for example, google geocode/timezone api key for date command:
//$telegram->setCommandConfig('date',
['google_api_key' => 'your_google_api_key_here']
);
////Logging
////
Logging
//$telegram->setLogRequests(true);
//$telegram->setLogPath($BOT_NAME
.
'.log');
//$telegram->setLogPath($BOT_NAME
.
'.log');
//$telegram->setLogVerbosity(3);
//$telegram->setDownloadPath("../Download");
//$telegram->setUploadPath("../Upload");
//// Set custom Upload and Download path
//$telegram->setDownloadPath('../Download');
//$telegram->setUploadPath('../Upload');
//
h
andle telegram webhook request
//
H
andle telegram webhook request
$telegram
->
handle
();
}
catch
(
Longman\TelegramBot\Exception\TelegramException
$e
)
{
//
Silence is gold
!
//
Silence is golden
!
// log telegram errors
// echo $e;
}
examples/set.php
View file @
61481e19
<?php
//Composer Loader
$dir
=
realpath
(
__DIR__
.
'/..'
);
$loader
=
require
$dir
.
'/vendor/autoload.php'
;
// Load composer
require
__DIR__
.
'/vendor/autoload.php'
;
$API_KEY
=
'your_bot_api_key'
;
$BOT_NAME
=
'namebot'
;
$
link
=
'https://yourdomain/yourpath_to_
hook.php'
;
$
hook_url
=
'https://yourdomain/path/to/
hook.php'
;
try
{
//
c
reate Telegram API object
//
C
reate Telegram API object
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_NAME
);
// set webhook
$result
=
$telegram
->
setWebHook
(
$link
);
//Uncomment to use certificate
//$result = $telegram->setWebHook($link, $path_certificate);
// Set webhook
$result
=
$telegram
->
setWebHook
(
$hook_url
);
// Uncomment to use certificate
//$result = $telegram->setWebHook($hook_url, $path_certificate);
if
(
$result
->
isOk
())
{
echo
$result
->
getDescription
();
}
...
...
examples/unset.php
View file @
61481e19
<?php
//
Composer Load
er
$loader
=
require
__DIR__
.
'/vendor/autoload.php'
;
//
Load compos
er
require
__DIR__
.
'/vendor/autoload.php'
;
$API_KEY
=
'your_bot_api_key'
;
$BOT_NAME
=
'namebot'
;
try
{
//
c
reate Telegram API object
//
C
reate Telegram API object
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_NAME
);
// set webhook
// Unset webhook
$result
=
$telegram
->
unsetWebHook
();
//Uncomment to use certificate
//$result = $telegram->setWebHook($link, $path_certificate);
if
(
$result
->
isOk
())
{
echo
$result
->
getDescription
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment