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
d1b4f1ce
Unverified
Commit
d1b4f1ce
authored
Oct 10, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix sendtochannel command to use updated code and use new Keyboard entities.
parent
3120727f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
27 deletions
+30
-27
SendtochannelCommand.php
src/Commands/AdminCommands/SendtochannelCommand.php
+30
-27
No files found.
src/Commands/AdminCommands/SendtochannelCommand.php
View file @
d1b4f1ce
...
...
@@ -10,12 +10,11 @@
namespace
Longman\TelegramBot\Commands\AdminCommands
;
use
Longman\TelegramBot\Entities\Keyboard
;
use
Longman\TelegramBot\Request
;
use
Longman\TelegramBot\Conversation
;
use
Longman\TelegramBot\Commands\AdminCommand
;
use
Longman\TelegramBot\Entities\Message
;
use
Longman\TelegramBot\Entities\ReplyKeyboardHide
;
use
Longman\TelegramBot\Entities\ReplyKeyboardMarkup
;
use
Longman\TelegramBot\Exception\TelegramException
;
class
SendtochannelCommand
extends
AdminCommand
...
...
@@ -67,7 +66,7 @@ class SendtochannelCommand extends AdminCommand
$type
=
$message
->
getType
();
// 'Cast' the command type into message to protect the machine state
// if the commmad is recalled when the conversation is already started
$type
=
(
$type
===
'command'
)
?
'Message'
:
$type
;
in_array
(
$type
,
[
'command'
,
'text'
],
true
)
&&
$type
=
'message'
;
$text
=
trim
(
$message
->
getText
(
true
));
$text_yes_or_no
=
(
$text
===
'Yes'
||
$text
===
'No'
);
...
...
@@ -78,7 +77,9 @@ class SendtochannelCommand extends AdminCommand
// Conversation
$this
->
conversation
=
new
Conversation
(
$user_id
,
$chat_id
,
$this
->
getName
());
$notes
=
&
$this
->
conversation
->
notes
;
$notes
=
&
$this
->
conversation
->
notes
;
!
is_array
(
$notes
)
&&
$notes
=
[];
$channels
=
(
array
)
$this
->
getConfig
(
'your_channel'
);
if
(
isset
(
$notes
[
'state'
]))
{
...
...
@@ -91,12 +92,12 @@ class SendtochannelCommand extends AdminCommand
switch
(
$state
)
{
case
-
1
:
// getConfig has not been configured asking for channel to administer
if
(
$type
!==
'
M
essage'
||
$text
===
''
)
{
if
(
$type
!==
'
m
essage'
||
$text
===
''
)
{
$notes
[
'state'
]
=
-
1
;
$this
->
conversation
->
update
();
$data
[
'text'
]
=
'Insert the channel name: (@yourchannel)'
;
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardH
ide
([
'selective'
=>
true
]);
$data
[
'reply_markup'
]
=
Keyboard
::
h
ide
([
'selective'
=>
true
]);
$result
=
Request
::
sendMessage
(
$data
);
break
;
...
...
@@ -110,7 +111,7 @@ class SendtochannelCommand extends AdminCommand
default
:
case
0
:
// getConfig has been configured choose channel
if
(
$type
!==
'
M
essage'
||
!
in_array
(
$text
,
$channels
,
true
))
{
if
(
$type
!==
'
m
essage'
||
!
in_array
(
$text
,
$channels
,
true
))
{
$notes
[
'state'
]
=
0
;
$this
->
conversation
->
update
();
...
...
@@ -118,7 +119,7 @@ class SendtochannelCommand extends AdminCommand
foreach
(
$channels
as
$channel
)
{
$keyboard
[]
=
[
$channel
];
}
$data
[
'reply_markup'
]
=
new
ReplyKeyboardMarkup
(
$data
[
'reply_markup'
]
=
new
Keyboard
(
[
'keyboard'
=>
$keyboard
,
'resize_keyboard'
=>
true
,
...
...
@@ -137,11 +138,11 @@ class SendtochannelCommand extends AdminCommand
// no break
case
1
:
insert
:
if
((
$type
===
'
M
essage'
&&
$text
===
''
)
||
$notes
[
'last_message_id'
]
===
$message
->
getMessageId
())
{
if
((
$type
===
'
m
essage'
&&
$text
===
''
)
||
$notes
[
'last_message_id'
]
===
$message
->
getMessageId
())
{
$notes
[
'state'
]
=
1
;
$this
->
conversation
->
update
();
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardH
ide
([
'selective'
=>
true
]);
$data
[
'reply_markup'
]
=
Keyboard
::
h
ide
([
'selective'
=>
true
]);
$data
[
'text'
]
=
'Insert the content you want to share: text, photo, audio...'
;
$result
=
Request
::
sendMessage
(
$data
);
break
;
...
...
@@ -156,8 +157,8 @@ class SendtochannelCommand extends AdminCommand
$this
->
conversation
->
update
();
// Execute this just with object that allow caption
if
(
$notes
[
'message_type'
]
===
'Video'
||
$notes
[
'message_type'
]
===
'Photo'
)
{
$data
[
'reply_markup'
]
=
new
ReplyKeyboardMarkup
(
if
(
in_array
(
$notes
[
'message_type'
],
[
'video'
,
'photo'
],
true
)
)
{
$data
[
'reply_markup'
]
=
new
Keyboard
(
[
'keyboard'
=>
[[
'Yes'
,
'No'
]],
'resize_keyboard'
=>
true
,
...
...
@@ -178,12 +179,12 @@ class SendtochannelCommand extends AdminCommand
$notes
[
'last_message_id'
]
=
$message
->
getMessageId
();
// no break
case
3
:
if
(
$notes
[
'set_caption'
]
&&
(
$notes
[
'last_message_id'
]
===
$message
->
getMessageId
()
||
$type
!==
'
M
essage'
))
{
if
(
$notes
[
'set_caption'
]
&&
(
$notes
[
'last_message_id'
]
===
$message
->
getMessageId
()
||
$type
!==
'
m
essage'
))
{
$notes
[
'state'
]
=
3
;
$this
->
conversation
->
update
();
$data
[
'text'
]
=
'Insert caption:'
;
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardH
ide
([
'selective'
=>
true
]);
$data
[
'reply_markup'
]
=
Keyboard
::
h
ide
([
'selective'
=>
true
]);
$result
=
Request
::
sendMessage
(
$data
);
break
;
}
...
...
@@ -204,7 +205,7 @@ class SendtochannelCommand extends AdminCommand
}
$this
->
sendBack
(
new
Message
(
$notes
[
'message'
],
$this
->
telegram
->
getBotName
()),
$data
);
$data
[
'reply_markup'
]
=
new
ReplyKeyboardMarkup
(
$data
[
'reply_markup'
]
=
new
Keyboard
(
[
'keyboard'
=>
[[
'Yes'
,
'No'
]],
'resize_keyboard'
=>
true
,
...
...
@@ -226,7 +227,7 @@ class SendtochannelCommand extends AdminCommand
$notes
[
'last_message_id'
]
=
$message
->
getMessageId
();
// no break
case
5
:
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardH
ide
([
'selective'
=>
true
]);
$data
[
'reply_markup'
]
=
Keyboard
::
h
ide
([
'selective'
=>
true
]);
if
(
$notes
[
'post_message'
])
{
$data
[
'text'
]
=
$this
->
publish
(
...
...
@@ -265,35 +266,37 @@ class SendtochannelCommand extends AdminCommand
protected
function
sendBack
(
Message
$message
,
array
$data
)
{
$type
=
$message
->
getType
();
$type
=
(
$type
===
'command'
)
?
'Message'
:
$type
;
if
(
$type
===
'Message'
)
{
in_array
(
$type
,
[
'command'
,
'text'
],
true
)
&&
$type
=
'message'
;
if
(
$type
===
'message'
)
{
$data
[
'text'
]
=
$message
->
getText
(
true
);
}
elseif
(
$type
===
'
A
udio'
)
{
}
elseif
(
$type
===
'
a
udio'
)
{
$data
[
'audio'
]
=
$message
->
getAudio
()
->
getFileId
();
$data
[
'duration'
]
=
$message
->
getAudio
()
->
getDuration
();
$data
[
'performer'
]
=
$message
->
getAudio
()
->
getPerformer
();
$data
[
'title'
]
=
$message
->
getAudio
()
->
getTitle
();
}
elseif
(
$type
===
'
D
ocument'
)
{
}
elseif
(
$type
===
'
d
ocument'
)
{
$data
[
'document'
]
=
$message
->
getDocument
()
->
getFileId
();
}
elseif
(
$type
===
'
P
hoto'
)
{
}
elseif
(
$type
===
'
p
hoto'
)
{
$data
[
'photo'
]
=
$message
->
getPhoto
()[
0
]
->
getFileId
();
}
elseif
(
$type
===
'
S
ticker'
)
{
}
elseif
(
$type
===
'
s
ticker'
)
{
$data
[
'sticker'
]
=
$message
->
getSticker
()
->
getFileId
();
}
elseif
(
$type
===
'
V
ideo'
)
{
}
elseif
(
$type
===
'
v
ideo'
)
{
$data
[
'video'
]
=
$message
->
getVideo
()
->
getFileId
();
}
elseif
(
$type
===
'
V
oice'
)
{
}
elseif
(
$type
===
'
v
oice'
)
{
$data
[
'voice'
]
=
$message
->
getVoice
()
->
getFileId
();
}
elseif
(
$type
===
'
L
ocation'
)
{
}
elseif
(
$type
===
'
l
ocation'
)
{
$data
[
'latitude'
]
=
$message
->
getLocation
()
->
getLatitude
();
$data
[
'longitude'
]
=
$message
->
getLocation
()
->
getLongitude
();
}
$callback_path
=
'Longman\TelegramBot\Request'
;
$callback_function
=
'send'
.
$type
;
$callback_function
=
'send'
.
ucfirst
(
$type
)
;
if
(
!
method_exists
(
$callback_path
,
$callback_function
))
{
throw
new
TelegramException
(
'Methods: '
.
$callback_function
.
' not found in class Request.'
);
}
return
call_user_func_array
(
$callback_path
.
'::'
.
$callback_function
,
[
$data
]
);
return
$callback_path
::
$callback_function
(
$data
);
}
/**
...
...
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