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
1954213e
Commit
1954213e
authored
Feb 11, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revise README file and correct code snippets.
Prettify example code files.
parent
f11c153c
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
258 additions
and
200 deletions
+258
-200
README.md
README.md
+179
-122
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 @
1954213e
This diff is collapsed.
Click to expand it.
examples/getUpdatesCLI.php
View file @
1954213e
...
...
@@ -2,66 +2,65 @@
<?php
//README
//This configuration file is intented to run the bot with the webhook method
//Uncommented parameters must be filled
//Uncommented parameters must be filled
#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 with table prefix
//$telegram->enableMySQL($credentials, $BOT_NAME.'_');
// Enable MySQL
$telegram
->
enableMySQL
(
$mysql_credentials
);
//$telegram->addCommandsPath($COMMANDS_FOLDER);
//// Enable MySQL with table prefix
//$telegram->enableMySQL($mysql_credentials, $BOT_NAME . '_');
////Here you can enable admin interface ache the channel you want to manage
//// Add an additional commands path
//$telegram->addCommandsPath($commands_path);
//// 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
;
echo
$e
;
}
examples/hook.php
View file @
1954213e
<?php
//README
//This configuration file is inten
t
ed to run the bot with the webhook method.
//Uncommented parameters must be filled
//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 with table prefix
//$telegram->enableMySQL($credentials, $BOT_NAME.'_');
//// Enable MySQL
//$telegram->enableMySQL($mysql_credentials);
//$telegram->addCommandsPath($COMMANDS_FOLDER);
//// Enable MySQL with table prefix
//$telegram->enableMySQL($mysql_credentials, $BOT_NAME . '_');
////Here you can enable admin interface ache the channel you want to manage
//// Add an additional commands path
//$telegram->addCommandsPath($commands_path);
//// 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 @
1954213e
<?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 @
1954213e
<?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