Is there a way to use this plugin to send those posts out once a day in parallel to the existing process of sending newly published posts?
No, there is no built-in way to do such kind of scheduling.
is there a way I can use a php function in this plugin to send a post to telegram by coding it myself?
Yes, the plugin provides a utility function to send the posts to Telegram.
$post = get_post( $your_post_id );
wptelegram_p2tg_send_post( $post );
Wow, that’s amazing. Thanks so much!!
I added the code to execute the function. Here’s the logfile output after doing that:
[2023-06-11 18:18:13]
{"post-506476-publish":{"before":{"trigger":"non_wp","request_type":null},"form_data":{"send2tg":null,"override_switch":false},"rules":{"apply":true,"sent2tg":"2023-03-11 19:12:57"},"finish":{"ok":false,"processed":[]},"after":{"result":"delayed 1"}}}
[2023-06-11 18:19:14]
{"post-506476-publish":{"before":{"trigger":"delayed_post","request_type":"DOING_CRON"},"form_data":{"send2tg":null,"override_switch":false},"rules":{"apply":false,"sent2tg":"2023-03-11 19:12:57"},"finish":{"ok":true,"processed":[]},"after":{"result":"441:524"}}}
Does that mean the post was submitted fine? I’m asking because I don’t see it come through in Telegram.
Just add this line before the above code
add_filter( 'wptelegram_p2tg_delay_in_posting', '__return_zero' );
That made it work, thanks very much!
I’ve noticed just now that two of the new posts were submitted in duplicate each. Could the above interfere with existing ongoing posting of new content? It could also have been an intermittent issue, I’ll keep monitoring it.
Yes, the above code doesn’t change the default behaviour of the plugin and thus it sends the post.
Actually now the posts are coming in normally, maybe it’s only in that brief moment when the above function happened and other plugin tasks are running simultaneously.
In any case, thanks very much for the swift support!
Cool. I’m glad it works now.
You may write a review about your experience with the plugin
https://ww.wp.xz.cn/support/plugin/wptelegram/reviews/#new-post
Done! One more question: Is there a function I can use where I can put together the entire string that’s submitted myself instead of passing the post object?
Is there a function I can use where I can put together the entire string that’s submitted myself instead of passing the post object?
You can directly use the Bot API library bundled with the plugin to send any type of messages you want.
$bot_token = WPTG()->options()->get( 'bot_token' );
$bot_api = new \WPTelegram\BotAPI\API( $bot_token );
$channels = WPTG()->options()->get( 'channels', [] );
foreach ( $channels as $channel ) {
$bot_api->sendMessage( [
'chat_id' => $channel,
'text' => 'Hello World',
] );
}
Thanks Irshad! I’ve tried that code but it doesn’t seem to return any value for $channels so it never makes it into the foreach loop.
I guess I could just hardcode the channel_id, trying that!
yes, that made it work, thanks again!!
Oh sorry, it should be
$channels = WPTG()->options()->get_path( 'p2tg.channels', [] );
Great, that fixed it, thanks!