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
a93bf5b5
Commit
a93bf5b5
authored
Feb 26, 2016
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sent to channel works without configuration
parent
5adfab27
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
17 deletions
+33
-17
SendtochannelCommand.php
src/Commands/AdminCommands/SendtochannelCommand.php
+33
-17
No files found.
src/Commands/AdminCommands/SendtochannelCommand.php
View file @
a93bf5b5
...
@@ -26,7 +26,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -26,7 +26,7 @@ class SendtochannelCommand extends AdminCommand
protected
$name
=
'sendtochannel'
;
protected
$name
=
'sendtochannel'
;
protected
$description
=
'Send message to a channel'
;
protected
$description
=
'Send message to a channel'
;
protected
$usage
=
'/sendtochannel <message to send>'
;
protected
$usage
=
'/sendtochannel <message to send>'
;
protected
$version
=
'0.1.
2
'
;
protected
$version
=
'0.1.
3
'
;
protected
$need_mysql
=
true
;
protected
$need_mysql
=
true
;
/**#@-*/
/**#@-*/
...
@@ -39,35 +39,51 @@ class SendtochannelCommand extends AdminCommand
...
@@ -39,35 +39,51 @@ class SendtochannelCommand extends AdminCommand
$chat_id
=
$message
->
getChat
()
->
getId
();
$chat_id
=
$message
->
getChat
()
->
getId
();
$user_id
=
$message
->
getFrom
()
->
getId
();
$user_id
=
$message
->
getFrom
()
->
getId
();
$type
=
$message
->
getType
();
$type
=
$message
->
getType
();
//'Cast' the command type into message this protect the machine state
// 'Cast' the command type into message this protect the machine state
//if the commmad is recolled when the conversation is already started
// if the commmad is recolled when the conversation is already started
if
(
$type
==
'command'
)
{
$this
->
reply_to_message
=
isset
(
$data
[
'reply_to_message'
])
?
$data
[
'reply_to_message'
]
:
null
;
$type
=
"Message"
;
$type
=
(
$type
==
'command'
)
?
'Message'
:
$type
;
}
$text
=
trim
(
$message
->
getText
(
true
));
$text
=
trim
(
$message
->
getText
(
true
));
$data
=
[];
$data
=
[];
$data
[
'chat_id'
]
=
$chat_id
;
$data
[
'chat_id'
]
=
$chat_id
;
//
tracking
//
Conversation
$conversation
=
new
Conversation
(
$user_id
,
$chat_id
,
$this
->
getName
());
$conversation
=
new
Conversation
(
$user_id
,
$chat_id
,
$this
->
getName
());
$conversation
->
start
();
$conversation
->
start
();
$session
=
$conversation
->
getData
();
$session
=
$conversation
->
getData
();
$channels
=
(
array
)
$this
->
getConfig
(
'your_channel'
);
if
(
!
isset
(
$session
[
'state'
]))
{
if
(
!
isset
(
$session
[
'state'
]))
{
$state
=
'0'
;
$state
=
(
count
(
$channels
)
==
0
)
?
-
1
:
0
;
$session
[
'last_message_id'
]
=
$message
->
getMessageId
();
$session
[
'last_message_id'
]
=
$message
->
getMessageId
();
}
else
{
}
else
{
$state
=
$session
[
'state'
];
$state
=
$session
[
'state'
];
}
}
switch
(
$state
)
{
case
-
1
:
// getConfig has not been configured asking for channel to administer
if
(
$type
!=
'Message'
||
empty
(
$text
))
{
$channels
=
(
array
)
$this
->
getConfig
(
'your_channel'
)
;
$session
[
'state'
]
=
'-1'
;
//echo count($channels) . "\n"
;
$conversation
->
update
(
$session
)
;
switch
(
$state
)
{
$data
[
'text'
]
=
'Insert the channel name: (@yourchannel)'
;
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardHide
([
'selective'
=>
true
]);
$result
=
Request
::
sendMessage
(
$data
);
break
;
}
$session
[
'channel'
]
=
$text
;
$session
[
'last_message_id'
]
=
$message
->
getMessageId
();
// Jump to state 1
goto
insert
;
// no break
default
:
default
:
case
0
:
case
0
:
if
(
$type
!=
'Message'
||
!
in_array
(
trim
(
$text
),
$channels
))
{
// getConfig has been configured choose channel
if
(
$type
!=
'Message'
||
!
in_array
(
$text
,
$channels
))
{
$session
[
'state'
]
=
'0'
;
$session
[
'state'
]
=
'0'
;
$conversation
->
update
(
$session
);
$conversation
->
update
(
$session
);
...
@@ -85,7 +101,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -85,7 +101,7 @@ class SendtochannelCommand extends AdminCommand
);
);
$data
[
'reply_markup'
]
=
$reply_keyboard_markup
;
$data
[
'reply_markup'
]
=
$reply_keyboard_markup
;
$data
[
'text'
]
=
'Select a channel'
;
$data
[
'text'
]
=
'Select a channel'
;
if
(
$type
!=
'Message'
||
!
in_array
(
trim
(
$text
)
,
$channels
))
{
if
(
$type
!=
'Message'
||
!
in_array
(
$text
,
$channels
))
{
$data
[
'text'
]
=
'Select a channel from the keyboard:'
;
$data
[
'text'
]
=
'Select a channel from the keyboard:'
;
}
}
$result
=
Request
::
sendMessage
(
$data
);
$result
=
Request
::
sendMessage
(
$data
);
...
@@ -96,6 +112,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -96,6 +112,7 @@ class SendtochannelCommand extends AdminCommand
// no break
// no break
case
1
:
case
1
:
insert
:
if
(
$session
[
'last_message_id'
]
==
$message
->
getMessageId
()
||
(
$type
==
'Message'
&&
empty
(
$text
)))
{
if
(
$session
[
'last_message_id'
]
==
$message
->
getMessageId
()
||
(
$type
==
'Message'
&&
empty
(
$text
)))
{
$session
[
'state'
]
=
1
;
$session
[
'state'
]
=
1
;
$conversation
->
update
(
$session
);
$conversation
->
update
(
$session
);
...
@@ -115,6 +132,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -115,6 +132,7 @@ class SendtochannelCommand extends AdminCommand
$session
[
'state'
]
=
2
;
$session
[
'state'
]
=
2
;
$conversation
->
update
(
$session
);
$conversation
->
update
(
$session
);
// Execute this just with object that allow caption
if
(
$session
[
'message_type'
]
==
'Video'
||
$session
[
'message_type'
]
==
'Photo'
)
{
if
(
$session
[
'message_type'
]
==
'Video'
||
$session
[
'message_type'
]
==
'Photo'
)
{
$keyboard
=
[[
'Yes'
,
'No'
]];
$keyboard
=
[[
'Yes'
,
'No'
]];
$reply_keyboard_markup
=
new
ReplyKeyboardMarkup
(
$reply_keyboard_markup
=
new
ReplyKeyboardMarkup
(
...
@@ -221,7 +239,6 @@ class SendtochannelCommand extends AdminCommand
...
@@ -221,7 +239,6 @@ class SendtochannelCommand extends AdminCommand
$result
=
Request
::
sendMessage
(
$data
);
$result
=
Request
::
sendMessage
(
$data
);
break
;
break
;
}
}
return
$result
;
return
$result
;
}
}
...
@@ -271,7 +288,6 @@ class SendtochannelCommand extends AdminCommand
...
@@ -271,7 +288,6 @@ class SendtochannelCommand extends AdminCommand
throw
new
TelegramException
(
'Methods: '
.
$callback_function
.
' not found in class Request.'
);
throw
new
TelegramException
(
'Methods: '
.
$callback_function
.
' not found in class Request.'
);
}
}
$result
=
call_user_func_array
(
$callback_path
.
'::'
.
$callback_function
,
array
(
$data
));
return
call_user_func_array
(
$callback_path
.
'::'
.
$callback_function
,
array
(
$data
));
return
$result
;
}
}
}
}
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