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
0a3ee2e5
Commit
0a3ee2e5
authored
Feb 26, 2016
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1-line sendtochannel without db
parent
a93bf5b5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
19 deletions
+55
-19
SendtochannelCommand.php
src/Commands/AdminCommands/SendtochannelCommand.php
+55
-19
No files found.
src/Commands/AdminCommands/SendtochannelCommand.php
View file @
0a3ee2e5
...
@@ -41,7 +41,6 @@ class SendtochannelCommand extends AdminCommand
...
@@ -41,7 +41,6 @@ class SendtochannelCommand extends AdminCommand
$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
$this
->
reply_to_message
=
isset
(
$data
[
'reply_to_message'
])
?
$data
[
'reply_to_message'
]
:
null
;
$type
=
(
$type
==
'command'
)
?
'Message'
:
$type
;
$type
=
(
$type
==
'command'
)
?
'Message'
:
$type
;
$text
=
trim
(
$message
->
getText
(
true
));
$text
=
trim
(
$message
->
getText
(
true
));
...
@@ -169,8 +168,8 @@ class SendtochannelCommand extends AdminCommand
...
@@ -169,8 +168,8 @@ class SendtochannelCommand extends AdminCommand
$result
=
Request
::
sendMessage
(
$data
);
$result
=
Request
::
sendMessage
(
$data
);
break
;
break
;
}
}
$session
[
'caption'
]
=
$text
;
$session
[
'last_message_id'
]
=
$message
->
getMessageId
();
$session
[
'last_message_id'
]
=
$message
->
getMessageId
();
$session
[
'caption'
]
=
$text
;
// no break
// no break
case
4
:
case
4
:
if
(
$session
[
'last_message_id'
]
==
$message
->
getMessageId
()
||
!
(
$text
==
'Yes'
||
$text
==
'No'
))
{
if
(
$session
[
'last_message_id'
]
==
$message
->
getMessageId
()
||
!
(
$text
==
'Yes'
||
$text
==
'No'
))
{
...
@@ -200,7 +199,6 @@ class SendtochannelCommand extends AdminCommand
...
@@ -200,7 +199,6 @@ class SendtochannelCommand extends AdminCommand
]
]
);
);
$data
[
'reply_markup'
]
=
$reply_keyboard_markup
;
$data
[
'reply_markup'
]
=
$reply_keyboard_markup
;
$result
=
Request
::
sendMessage
(
$data
);
$result
=
Request
::
sendMessage
(
$data
);
}
}
break
;
break
;
...
@@ -214,34 +212,71 @@ class SendtochannelCommand extends AdminCommand
...
@@ -214,34 +212,71 @@ class SendtochannelCommand extends AdminCommand
// no break
// no break
case
5
:
case
5
:
$conversation
->
stop
();
$conversation
->
stop
();
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardHide
([
'selective'
=>
true
]);
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardHide
([
'selective'
=>
true
]);
if
(
$session
[
'post_message'
])
{
if
(
$session
[
'post_message'
])
{
$data1
=
[];
$data
[
'text'
]
=
$this
->
publish
(
new
Message
(
$session
[
'message'
],
'anystring'
),
$session
[
'channel'
],
$session
[
'caption'
]);
$data1
[
'chat_id'
]
=
$session
[
'channel'
];
if
(
$session
[
'set_caption'
])
{
$data1
[
'caption'
]
=
$session
[
'caption'
];
}
$result
=
$this
->
sendBack
(
new
Message
(
$session
[
'message'
],
'thisbot'
),
$data1
);
$text_back
=
'Message not sent to: '
.
$session
[
'channel'
]
.
"
\n
"
.
'- The channel exist?'
.
"
\n
"
.
'- Is the bot admin of the channel?'
;
if
(
$result
->
isOk
())
{
$text_back
=
'Message sent succesfully to: '
.
$session
[
'channel'
];
}
$data
[
'text'
]
=
$text_back
;
$result
=
Request
::
sendMessage
(
$data
);
$result
=
Request
::
sendMessage
(
$data
);
break
;
break
;
}
}
$data
[
'text'
]
=
'Abort by user, message not sent..'
;
$data
[
'text'
]
=
'Abort by user, message not sent..'
;
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardHide
([
'selective'
=>
true
]);
$result
=
Request
::
sendMessage
(
$data
);
$result
=
Request
::
sendMessage
(
$data
);
break
;
break
;
}
}
return
$result
;
return
$result
;
}
}
/**
* {@inheritdoc}
*/
public
function
executeNoDB
()
{
$message
=
$this
->
getMessage
();
$text
=
trim
(
$message
->
getText
(
true
));
$chat_id
=
$message
->
getChat
()
->
getId
();
$data
=
[];
$data
[
'chat_id'
]
=
$chat_id
;
if
(
empty
(
$text
))
{
$data
[
'text'
]
=
'Usage: /sendtochannel <text>'
;
}
else
{
$channels
=
(
array
)
$this
->
getConfig
(
'your_channel'
);
$first_channel
=
$channels
[
0
];
$data
[
'text'
]
=
$this
->
publish
(
new
Message
(
$message
->
reflect
(),
'anystring'
),
$first_channel
);
}
return
Request
::
sendMessage
(
$data
);
}
/**
* Publish
*
* Publish a message in a channel and retun succecs or fail message
* @param Longman\TelegramBot\Entities\Message $message
* @param int $channel
* @param string|null $caption
*
* @return string
*/
protected
function
publish
(
Message
$message
,
$channel
,
$caption
=
null
)
{
$data
=
[
'chat_id'
=>
$channel
,
'caption'
=>
$caption
,
];
if
(
$this
->
sendBack
(
$message
,
$data
)
->
isOk
())
{
$response
=
'Message sent succesfully to: '
.
$channel
;
}
else
{
$response
=
'Message not sent to: '
.
$channel
.
"
\n
"
.
'- The channel exist?'
.
"
\n
"
.
'- Is the bot admin of the channel?'
;
}
return
$response
;
}
/**
/**
* SendBack
* SendBack
*
*
...
@@ -258,11 +293,12 @@ class SendtochannelCommand extends AdminCommand
...
@@ -258,11 +293,12 @@ class SendtochannelCommand extends AdminCommand
*
*
* @return Longman\TelegramBot\Entities\ServerResponse
* @return Longman\TelegramBot\Entities\ServerResponse
*/
*/
p
ublic
function
sendBack
(
Message
$message
,
array
$data
)
p
rotected
function
sendBack
(
Message
$message
,
array
$data
)
{
{
$type
=
$message
->
getType
();
$type
=
$message
->
getType
();
$type
=
(
$type
==
'command'
)
?
'Message'
:
$type
;
if
(
$type
==
'Message'
)
{
if
(
$type
==
'Message'
)
{
$data
[
'text'
]
=
$message
->
getText
();
$data
[
'text'
]
=
$message
->
getText
(
true
);
}
elseif
(
$type
==
'Audio'
)
{
}
elseif
(
$type
==
'Audio'
)
{
$data
[
'audio'
]
=
$message
->
getAudio
()
->
getFileId
();
$data
[
'audio'
]
=
$message
->
getAudio
()
->
getFileId
();
$data
[
'duration'
]
=
$message
->
getAudio
()
->
getDuration
();
$data
[
'duration'
]
=
$message
->
getAudio
()
->
getDuration
();
...
...
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