News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Telegram Autopost Bot

Started by vbgamer45, April 11, 2020, 05:57:59 AM

Previous topic - Next topic

Matthias

Maybe or not.
Thinking about the telegram bot API...
I had though of it and got some result for my own, it changes from time to time.
https://core.telegram.org/bots/api



Quality first

kesulin

this mod not allow bold text? any solutions about it?

Forget it, I find the solution.

-Open telegram2.php
-Find function "telegram_sendCURL($message)"
Change:
curl_setopt($ch, CURLOPT_URL,  'https://api.telegram.org/bot'.$modSettings['telegram_enable_bot_auth_token'].'/sendMessage?chat_id=' .$modSettings['telegram_enable_chat_id'] . "&text=". urlencode($message['text']));

to

curl_setopt($ch, CURLOPT_URL,  'https://api.telegram.org/bot'.$modSettings['telegram_enable_bot_auth_token'].'/sendMessage?chat_id=' .$modSettings['telegram_enable_chat_id'] . "&text=". urlencode($message['text'])."&parse_mode=html");

now html tags works

mpcgferreira

Hello to all. I already setup all but not working what can be missing any help?

shadav

Quote from: mpcgferreira on October 19, 2021, 04:33:30 PMHello to all. I already setup all but not working what can be missing any help?
need a bit more info other than it's not working
how is it not working?
any errors?
what version of smf are you using?
any errors in your smf logs?
any errors in your server logs?

mpcgferreira

Quote from: shadav on October 19, 2021, 04:39:17 PM
Quote from: mpcgferreira on October 19, 2021, 04:33:30 PMHello to all. I already setup all but not working what can be missing any help?
need a bit more info other than it's not working
how is it not working?
any errors?
what version of smf are you using?
any errors in your smf logs?
any errors in your server logs?

Thanks for reply. I use SMF 2.0.18
I setup api token on the right place. Put the channel id but any changes made on the forum dont get any msg on the telegram.
The only error i get is these: "2: Parameter 1 to RIAST_Titles() expected to be a reference, value given"
On the server side dont have erros.

These mod need any cron?


mpcgferreira

Quote from: mpcgferreira on October 19, 2021, 04:46:26 PM
Quote from: shadav on October 19, 2021, 04:39:17 PM
Quote from: mpcgferreira on October 19, 2021, 04:33:30 PMHello to all. I already setup all but not working what can be missing any help?
need a bit more info other than it's not working
how is it not working?
any errors?
what version of smf are you using?
any errors in your smf logs?
any errors in your server logs?

Thanks for reply. I use SMF 2.0.18
I setup api token on the right place. Put the channel id but any changes made on the forum dont get any msg on the telegram.
The only error i get is these: "2: Parameter 1 to RIAST_Titles() expected to be a reference, value given"
On the server side dont have erros.

These mod need any cron?



About these problem solved "2: Parameter 1 to RIAST_Titles() expected to be a reference, value given"

vbgamer45

RIAST_Title is not part of this mod.

This mod does like cURL to be enabled in order to post. You can see if it is by checking your phpinfo page.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

mpcgferreira

Quote from: vbgamer45 on October 20, 2021, 11:03:22 AMRIAST_Title is not part of this mod.

This mod does like cURL to be enabled in order to post. You can see if it is by checking your phpinfo page.

Hello thanks for the reply,
Just check and curl is enable for the php version.

I have php 7.4
0 errors on the log

---

One question on the telegram bot token the code is similar to these;

Telegram Bot Token -> 2072778772:AAFqwoJRy5LIgThTsddt7fLQobWYYvwOHJY

And on the channel id the code is similar to these:

Telegram Chat ID -> 1001666685967


mpcgferreira


vbgamer45

My bot token looks similar.
And chat id looks like that
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

mpcgferreira

Quote from: vbgamer45 on October 20, 2021, 11:27:32 AMMy bot token looks similar.
And chat id looks like that

Hello thanks for the reply. Any idea why my don´t work  if setup is good?

I get my chat id from MissRoseBot
I get my token for the bot from BotFather
I add the boot to the channel as admin

I am lost!?!?!

mpcgferreira

#71
Just try something. Create a reply to a topic and check for errors and get 2

First

"JSON Syntax error"

Second

400:<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.18.0</center>
</body>
</html>

---

If we search on google for these error we get "The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing)."

---

The MOD have any problem with SMF 2.0.18? or any of these MOD have impact the telegram MOD
Google Analytics Code
Optimus for SMF
SEO Sitemap   
RSS Feed Poster   
Pretty URLs   

vbgamer45

Test with your own url replace the options in the url with your settings
https://api.telegram.org/bot'; . $modSettings['telegram_enable_bot_auth_token'] . '/sendMessage?chat_id=' . $modSettings['telegram_enable_chat_id'] . "&text=" . urlencode($message['text']
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

mpcgferreira

Quote from: vbgamer45 on October 20, 2021, 11:51:23 AMTest with your own url replace the options in the url with your settings
https://api.telegram.org/bot' [nofollow]; . $modSettings['telegram_enable_bot_auth_token'] . '/sendMessage?chat_id=' . $modSettings['telegram_enable_chat_id'] . "&text=" . urlencode($message['text']

I put that on browser url and get these: {"ok":false,"error_code":404,"description":"Not Found"}

vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

mpcgferreira

Hello,
Now i get these {"ok":false,"error_code":400,"description":"Bad Request: chat not found"}

chat no found is strange because i get the ID from MissRoseBot

vbgamer45

Chat ID is tricky to get. It has been a long time though i don't remember exactly.

From searching
You have to add the bot to be an administrator of the channel before it can send messages to the channel.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

mpcgferreira

Quote from: vbgamer45 on October 20, 2021, 01:47:33 PMChat ID is tricky to get. It has been a long time though i don't remember exactly.

From searching
You have to add the bot to be an administrator of the channel before it can send messages to the channel.

Yes i know that!
The ID i need is the Group or Channel ID correct?
or
The user bot user ID?

vbgamer45

It might user bot id. I don't remember. I just remember it was not easy to find out. I had to talk to a bot on telegram to get the chat id.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

mpcgferreira

Thanks,
I try to find more info.

But i drop these link that can be usefull.

https://stackoverflow.com/questions/32423837/telegram-bot-how-to-get-a-group-chat-id [nofollow]

Advertisement: