upd: 09.11.20 SOlVED I've made the telegram bot that working good in single conversations of a groups. However right now I want it to send messages right in my channel.
When I'm writing script(after i write straigt to the bot to invoke it by command /start)
import telebot
token = '...'
bot = telebot.TeleBot(token)
#bot.message_handler(commands=['start'])
def default_test(message):
answer = 'Привет!'
bot.send_message('#hello_danishere', answer)
bot.polling(none_stop=True, interval=0)
or doing a html query
https://api.telegram.org/bot/sendMessage?chat_id=#hello_danishere&text=123
i'm getting an error.
{"ok":false,"error_code":400,"description":"Bad Request: chat not found"}
I've already done this things that found in internet:
Give the administator permissions to the bot
Used #mychannelname instead of message.chat.id while invoking send_message
Written smthg in channel cause bot can reply only if you already written him.
SOlVED.
The thing is you need to check three things to success:
1.Your channel responding to link t.me/<nameofPUBLICchannel
2.Your bot has administrative permissions
3.You've already posted smtng on your channel
That helped me
Related
Telegram introduced Bot API 5.1 with ChatMemberUpdated and the fields my_chat_member and chat_member in the Update class.
But how to track when the user stopped the bot now if I'm using ConversationHandler?
Previously, my bot was waiting for commands like /cancel or /stop.
conversation_handler = ConversationHandler(
entry_points=...,
states=...,
fallbacks=[
# ...
MessageHandler(Filters.regex('^/(cancel|stop)$'), flow_stop_chat),
# ...
],
allow_reentry=True,
name=current_bot_label,
persistent=True,
)
How to do that correctly now using ChatMemberUpdated?
Catch the update using ChatMemberHandler (new in PTB v13.4) and check update.my_chat_member.new_chat_member.status to see if your bot was blocked. However blocking a bot is not quite the same as simply sending a /cancel command, so I'd suggest to keep the MessageHandler (or better yet, change it to CommandHandler(['cancel', 'stop'], flow_stop_chat))
I'm trying to set my bot's typing status by sending the following POST request (based on the API docs):
https://api.telegram.org/bot{{botToken}}/setTyping
{
peer: {{chat_id}},
typing: true,
action: 'sendMessageTypingAction'
}
I've tried a few variations of it, such as changing the url to be /messages.setTyping and sending the action as {"_":"sendMessageTypingAction"} as seen here, but all I get is:
{
"ok": false,
"error_code": 404,
"description": "Not Found: method not found"
}
Anyone know what I'm doing wrong?
Thanks to #tashakori for pointing me in the right direction towards the Bot API. For posterity, what I needed to do was:
https://api.telegram.org/bot{{botToken}}/sendChatAction
{
chat_id: {{chatId}},
action: 'typing'
}
The link you have mentioned above belongs to Telegram Core APIs which is used for handling ordinary accounts of Telegram. These so-called Core APIs are not related to Telegram Bot APIs.
The only API that is somehow similar to SetTyping for bots is AnswerCallbackQuery, which can be used only when responding to the user's interaction with inline keyboards. (you can send a text to the user, saying that there is a process running in the background and whenever the user's answer is ready, you can send it using APIs like sendMessage)
According to this https://developers.google.com/youtube/v3/guides/push_notifications
I can subscribe to a youtube channel & receive push notification for any new video.
My callback server is a php script which interprets POST/GET data:
<?php
if (isset($_GET['hub_challenge'])) {
print $_GET['hub_challenge'];
}
else {
$xml=file_get_contents("php://input");
file_put_contents('endpoint.txt',$xml);
}
?>
But $xml is empty. In the docs it says:
The YouTube Data API (v3) supports push notifications via
PubSubHubbub, a server-to-server publish/subscribe protocol for
Web-accessible resources. Notifications are pushed out to subscribers
via HTTP webhooks, which is much more efficient than polling-based
solutions.
But it does not specify how does it send the data....whether in POST body or in somewhere else.
So How do I get the atom feed in my script?
EDIT: I should probably ask a new question for this...but anyway....I tried this channel (https://www.youtube.com/channel/UCATp8LNTjzjNlLxdArp0Myg); but when I try to subscribe it says "restricted topic" (I did not provide token as it is a public channel). Same for any other channel ID. Is something wrong with my callback server? I also tried runscope url as a callback server for testing. But it did not help.
Others are having similar problems. Here is the issue log:
https://code.google.com/p/gdata-issues/issues/detail?id=7138
and related StackOverflow question:
Youtube API - Subscribing to Push Notifications
Unfortunately, no one seem to provide a solution although you can follow the issue and track any progress.
Yes it send data on the POST body . If you are using Express Nodejs add app.use(bodyParser.xml()) middleware to parse xml data
I wrote coffee script like below to integrate mailchimp and other service on Slack using Hubot.
Hubot do hear me and other team member comment, but won't hear mailchimp notification comment.
Anyone know how to solve it?
Thank you.
module.exports = (robot) ->
robot.hear /^(.*)( foo bar)$/i, (msg) ->
#Do something
I understand the reason why Hubot won't work when I read this Japanese Article.
http://qiita.com/Vexus2/items/aaf87212e7239132446b
Summary of this article is as below.
First, Hubot-slack don't support Bot to Bot.
And It will be fixed within this year.
(I saw an article which a Japanese developer asked support desk about this,
and he received reply as above.)
Secondary, If you can't wait that modification,
you should use Hubot-IRC adapter and Slack IRC instead of Hubot-Slack.
You can listen to other bot's messages by using
controller.on('bot_message', function (bot, message) {
console.log('message', message);
var attachment = message.attachments[0];
console.log('attachment', attachment);
});
There's an ugly-ish workaround: SlackBot, Slacks native bot is heard by hubot.
And it's a simple POST request to make it say something to a channel that your hubot can respond to.
E.g.
curl --data "\#hubot asci me OMG from SlackBot" 'https://my.slack.com/services/hooks/slackbot?token=<YOUR_SLACK_TOKEN>&channel=%23channel_that_hubot_is_in'
I've been implementing a small PHP script which will send Push Notifications to Apple's APN servers.
I've got a database with all device tokens that registered for push notifications within my App.
My script will query the database for the tokens and send them to Apple.
Everything works great with a big but... I manually inserted a wrong token into my table and executed the script again.
I've realized that after that wrong token is sent to Apple, all notifications after that won't reach the devices.
Apple seems not to return any OK if everything worked fine but it does send a KO code if something went wrong. I get an error from Apple for that wrong token but I don't get any response afterwards for all the other notifications.
I open only one connection for all the tokens inside the database.
I prepare a socket context with this line:
$streamContext = stream_context_create(array(
'ssl' => array(
'local_cert' => $this->signFile
)
));
Then start a communication channel with the APN servers:
$this->hFile = stream_socket_client(self::$serverUrl[$environment], $err, $errstr, 60, STREAM_CLIENT_CONNECT, $streamContext);
Finally I send the message:
fwrite($this->hFile, $command);
I thought of setting a new connection for every notification but I wanted to ask SO opinion first...
By the way, I know that PHP isn't the best choice for this but it came as a requirement from somewhere else and we are forced to set the system this way.
Thank you and have a nice day,
Alex.
I finally found a solution:
As soon as I detect that a token is invalid, I close the connection and open it again to start sending tokens right after the wrong one.