Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
phpeace
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
16
Issues
16
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PeaceLink
phpeace
Commits
6dd9459d
Commit
6dd9459d
authored
Oct 12, 2019
by
Francesco Iannuzzelli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#30
Telegram bot - Support images
parent
392f49e8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
20 deletions
+34
-20
classes/telegram.php
classes/telegram.php
+34
-20
No files found.
classes/telegram.php
View file @
6dd9459d
...
...
@@ -30,6 +30,7 @@
use
Formapro\TelegramBot\Bot
;
use
Formapro\TelegramBot\Update
;
use
Formapro\TelegramBot\SendMessage
;
use
Formapro\TelegramBot\SendPhoto
;
use
Formapro\TelegramBot\AnswerCallbackQuery
;
use
Formapro\TelegramBot\InlineKeyboardButton
;
use
Formapro\TelegramBot\InlineKeyboardMarkup
;
...
...
@@ -71,6 +72,8 @@ class TelegramBot
private
$inline_buttons
=
array
();
private
$images
=
array
();
/**
* Initialize local properties
*/
...
...
@@ -111,6 +114,9 @@ class TelegramBot
if
(
isset
(
$a
[
'menu'
]))
{
$response
.=
PHP_EOL
.
PHP_EOL
.
$this
->
MenuLookup
(
$a
[
'menu'
]);
}
if
(
isset
(
$a
[
'images'
])
&&
is_array
(
$a
[
'images'
]))
{
$this
->
images
=
$a
[
'images'
];
}
}
}
return
$response
?
$response
:
$boh
;
...
...
@@ -152,28 +158,36 @@ class TelegramBot
$fullname
=
"
$firstname
$lastname
"
;
// lookup
$response
=
$this
->
ActionLookup
(
$text
);
// variables replacements
$response
=
str_replace
(
'%NAME%'
,
$fullname
,
$response
);
//$msg = new SendMessage($id,"Hi there $fullname ($id - $username)!");
//$bot->sendMessage($msg);
$msg
=
new
SendMessage
(
$id
,
$response
);
// request phone
/*
$button = new KeyboardButton('Telefono');
$button->setRequestContact(true);
$keyboard = new ReplyKeyboardMarkup([[$button]]);
$keyboard->setOneTimeKeyboard(true);
*/
// Inline buttons
if
(
count
(
$this
->
inline_buttons
)
>
0
)
{
$buttons
=
[];
foreach
(
$this
->
inline_buttons
as
$item
)
{
$buttons
[]
=
InlineKeyboardButton
::
withTextAsCallbackData
(
strtoupper
(
$item
));
if
(
count
(
$this
->
images
)
>
0
)
{
$sendPhoto
=
new
SendPhoto
(
$id
,
$this
->
images
[
array_rand
(
$this
->
images
)]);
$sendPhoto
->
setCaption
(
$response
);
$bot
->
sendPhoto
(
$sendPhoto
);
$this
->
images
=
[];
}
else
{
// variables replacements
$response
=
str_replace
(
'%NAME%'
,
$fullname
,
$response
);
//$msg = new SendMessage($id,"Hi there $fullname ($id - $username)!");
//$bot->sendMessage($msg);
$msg
=
new
SendMessage
(
$id
,
$response
);
// request phone
/*
$button = new KeyboardButton('Telefono');
$button->setRequestContact(true);
$keyboard = new ReplyKeyboardMarkup([[$button]]);
$keyboard->setOneTimeKeyboard(true);
*/
// Inline buttons
if
(
count
(
$this
->
inline_buttons
)
>
0
)
{
$buttons
=
[];
foreach
(
$this
->
inline_buttons
as
$item
)
{
$buttons
[]
=
InlineKeyboardButton
::
withTextAsCallbackData
(
strtoupper
(
$item
));
}
$keyboard
=
new
InlineKeyboardMarkup
([
$buttons
]);
$msg
->
setReplyMarkup
(
$keyboard
);
$this
->
inline_buttons
=
[];
}
$keyboard
=
new
InlineKeyboardMarkup
([
$buttons
]);
$msg
->
setReplyMarkup
(
$keyboard
);
$bot
->
sendMessage
(
$msg
);
}
$bot
->
sendMessage
(
$msg
);
http_response_code
(
200
);
}
else
{
$bot
->
sendMessage
(
$msg
);
...
...
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