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
a812b42e
Commit
a812b42e
authored
Oct 20, 2015
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
README and phpcs
parent
15aade22
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
26 deletions
+96
-26
README.md
README.md
+42
-18
WhoamiCommand.php
src/Commands/WhoamiCommand.php
+1
-1
ImageCommand.php
src/CommandsExamples/ImageCommand.php
+45
-0
Chat.php
src/Entities/Chat.php
+1
-1
ServerResponse.php
src/Entities/ServerResponse.php
+4
-3
Request.php
src/Request.php
+3
-3
No files found.
README.md
View file @
a812b42e
...
...
@@ -23,7 +23,7 @@ all sorts to bring automated interactions to the mobile platform. This
Bot aims to provide a platform where one could simply write a plugin
and have interactions in a matter of minutes.
The Bot can:
-
retrive update with webhook and
by
getUpdate methods.
-
retrive update with webhook and getUpdate methods.
-
supports all types and methods according to Telegram API (2015 October 8).
-
handle commads in chat with other bots.
...
...
@@ -215,12 +215,49 @@ All types implemented according to Telegram API (2015 October 8).
### Methods New!
All methods implemented according to Telegram API (2015 October 8).
TODO example to use methods
###Send Photo
To send a local photo provide the file path as second param:
```
php
$result
=
Request
::
sendPhoto
(
$data
,
'image.jpg'
);
$data
[
'chat_id'
]
=
$chat_id
;
$result
=
Request
::
sendPhoto
(
$data
,
$this
->
telegram
->
getUploadPath
()
.
'/'
.
'image.jpg'
);
```
If you know the file_id of a previously uploaded file, just provide it in the fist param:
```
php
$data
[
'chat_id'
]
=
$chat_id
;
$data
[
'photo'
]
=
$file_id
;
$result
=
Request
::
sendPhoto
(
$data
);
```
*sendAudio*
,
*sendDocument*
,
*sendSticker*
,
*sendVideo*
and
*sendVoice*
works in the same way.
See
*ImageCommand.php*
for a full example.
####Send Chat Action
```
php
Request
::
sendChatAction
([
'chat_id'
=>
$chat_id
,
'action'
=>
'typing'
]);
```
####getUserProfilePhoto
Retrieve the user photo, see the
*WhoamiCommand.php*
for a full example.
####GetFile and dowloadFile
Get the file path and download it, see the
*WhoamiCommand.php*
for a full example.
#### Send message to all active chats
To do this you have to enable the Mysql connection.
Here's an example of use:
```
php
$results
=
$telegram
->
sendToActiveChats
(
'sendMessage'
,
//callback function to execute (see Request.php methods)
array
(
'text'
=>
'Hey! Checkout the new feature!!'
),
//Param to evaluate the request
true
,
//Send to chats (group chat)
true
,
//Send to users (single chat)
null
,
//'yyyy-mm-dd hh:mm:ss' date range from
null
//'yyyy-mm-dd hh:mm:ss' date range to
);
```
## Utilis
### MySQL storage (Recomended)
...
...
@@ -291,21 +328,8 @@ array('google_api_key'=>'your_google_api_key_here'));
### Upload and Download directory
You can overwrite the default Upload and download directory with:
```
php
```
### Send message to all active chats
To do this you have to enable the Mysql connection.
Here's an example of use:
```
php
$results
=
$telegram
->
sendToActiveChats
(
'sendMessage'
,
//callback function to execute (see Request.php methods)
array
(
'text'
=>
'Hey! Checkout the new feature!!'
),
//Param to evaluate the request
true
,
//Send to chats (group chat)
true
,
//Send to users (single chat)
null
,
//'yyyy-mm-dd hh:mm:ss' date range from
null
//'yyyy-mm-dd hh:mm:ss' date range to
);
$telegram
->
setDownloadPath
(
"yourpath/Download"
);
$telegram
->
setUploadPath
(
"yourpath../Upload"
);
```
### Logging
...
...
src/Commands/WhoamiCommand.php
View file @
a812b42e
...
...
@@ -66,7 +66,7 @@ class WhoamiCommand extends Command
$data
[
'chat_id'
]
=
$chat_id
;
$data
[
'reply_to_message_id'
]
=
$message_id
;
if
(
$totalcount
>
0
)
{
if
(
$totalcount
>
0
)
{
$photos
=
$UserProfilePhoto
->
getPhotos
();
//I pick the latest photo with the hight definition
$photo
=
$photos
[
0
][
2
];
...
...
src/CommandsExamples/ImageCommand.php
0 → 100644
View file @
a812b42e
<?php
/*
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Longman\TelegramBot\Commands
;
use
Longman\TelegramBot\Request
;
use
Longman\TelegramBot\Command
;
use
Longman\TelegramBot\Entities\Update
;
class
ImageCommand
extends
Command
{
protected
$name
=
'image'
;
protected
$description
=
'Send Image'
;
protected
$usage
=
'/image'
;
protected
$version
=
'1.0.0'
;
protected
$enabled
=
true
;
protected
$public
=
true
;
public
function
execute
()
{
$update
=
$this
->
getUpdate
();
$message
=
$this
->
getMessage
();
$chat_id
=
$message
->
getChat
()
->
getId
();
$text
=
$message
->
getText
(
true
);
$data
=
array
();
$data
[
'chat_id'
]
=
$chat_id
;
$data
[
'caption'
]
=
$text
;
//$result = Request::sendDocument($data,'structure.sql');
//$result = Request::sendSticker($data, $this->telegram->getUploadPath().'/'.'image.jpg');
$result
=
Request
::
sendPhoto
(
$data
,
$this
->
telegram
->
getUploadPath
()
.
'/'
.
'image.jpg'
);
return
$result
;
}
}
src/Entities/Chat.php
View file @
a812b42e
...
...
@@ -40,7 +40,7 @@ class Chat extends Entity
public
function
isGroupChat
()
{
if
(
$this
->
type
==
'group'
||
$this
->
id
<
0
)
{
if
(
$this
->
type
==
'group'
||
$this
->
id
<
0
)
{
return
true
;
}
else
{
return
false
;
...
...
src/Entities/ServerResponse.php
View file @
a812b42e
...
...
@@ -117,7 +117,8 @@ class ServerResponse extends Entity
{
return
$this
->
description
;
}
public
function
printError
(){
public
function
printError
()
{
return
'Error N: '
.
$this
->
getErrorCode
()
.
' Description: '
.
$this
->
getDescription
();
}
}
src/Request.php
View file @
a812b42e
...
...
@@ -178,12 +178,12 @@ class Request
$dirname
=
dirname
(
$loc_path
);
if
(
!
is_dir
(
$dirname
))
{
if
(
!
mkdir
(
$dirname
,
0755
,
true
))
{
if
(
!
mkdir
(
$dirname
,
0755
,
true
))
{
throw
new
TelegramException
(
'Directory '
.
$dirname
.
' cant be created'
);
}
}
# open file to write
$fp
=
fopen
(
$loc_path
,
'w+'
);
$fp
=
fopen
(
$loc_path
,
'w+'
);
if
(
$fp
===
false
)
{
throw
new
TelegramException
(
'File cant be created'
);
}
...
...
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