telegram bot: continue a conversation in private - telegram-bot

I am trying to create a bot that can be started from a chat group but continue the conversation privately.
My ConversationHandler is simple:
ConversationHandler(
entry_points=[CommandHandler('start', start)],
states={
ONE: [MessageHandler(Filters.text, get_type)],
TWO: [MessageHandler(Filters.text, get_category)]
},
fallbacks=[CommandHandler('cancel', cancel)],
allow_reentry=True
)
my first message (from start) it's sent to the private chat
update.message.from_user.id
And it works, since the conversation was started from the user.
The problem is that the bot does not recognize anything typed in the private chat as part of the conversation. If I set a echo msghandler, it uses it. If I don't have that, nothing happens.
How should I do that? Everything works fine if I start the conversation privately. Last resort I send a private message to ask the user to /start the conversation.

Related

CallbackQueryHandler or ConversationHandler for a message sent from bot class

Using python-telegram-bot, I have a bot running with very similar settings as for the other examples. On the other side i have parallel processes that allow me to send messages to users interacting with the bot periodically. The parallel proccess communicates with the users using:
bot = Bot(token=TELEGRAM_TOKEN)
def get_button_options():
keyboard = [[ InlineKeyboardButton("reply", callback_data='reply),]]
reply_markup = InlineKeyboardMarkup(keyboard)
return reply_markup
bot.send_message(chat_id=self.telegram_id, text=text, reply_markup=get_button_options())
The thing is, even if I'm capable to send messages to the user, the above code does not allow the user to interact with the bot (By that I mean that, once the user presses the button, the bot doesn't execute any callback). This is because I need either a CallbackQueryHandler or ConversationHandler within the bot.
However for the ConversationHandler I don't seem to find any appropiate entry_point, since it is a message sent from a parallel process. On the other hand, using the following CallbackQueryHandler (taken from the example) in the main bot doesn't seem to have any effect:
def button(update: Update, _: CallbackContext) -> None:
query = update.callback_query
# CallbackQueries need to be answered, even if no notification to the user is needed
# Some clients may have trouble otherwise. See https://core.telegram.org/bots/api#callbackquery
query.answer()
query.edit_message_text(text=f"Selected option: {query.data}")
in the main function, I have added the handler using updater.dispatcher.add_handler(CallbackQueryHandler(button))
Any ideas on how to solve that?
As said by #CallMeStag, the solution is the following:
ConversationHandler(
entry_points=[CallbackQueryHandler(button)])
the correct entry point is a CallbackQueryHandler, so then it captures the selected button

DiscordJS how to detect inhuman commands

I'm working on a Discord bot which handles a multiplayer game with rpg elements - those rpg elements allow users to perform different income activities in specified interval (best example would be EPIC RPG).
Considering the game is multiplayer and pretty much only interval based, I want to prevent players from using any automation, which allows them to take the top ranks with minimum effort and keep the game fair!
I'm currently running it in a small test server and already had a guy using something what allowed him to send those commands each 10 seconds (EDIT: from his personal user account), resulting in over 5000 commands within 16 hours. He's very mysterious about details of whatever he's using to achieve this outcome. I also found out he can even set multiple intervals at once which countered the solution I tried and will describe next.
What I tried
Implementing a captcha which randomly generates when user sends the command and temporary ban when user fails to complete the captcha - This is only a partial solution because he can still use the automation while doing other work arround and pass captcha when it pops
Implementing bonus captcha which generates when user sends the command in same interval twice in row - This only works if there is one timer, setting more timers counters this
So my question which is by now pretty much obvious I'd say is: How can I detect automation (interval patterns?) on those commands to effectively annoy those botters with captcha till they rather give up and play manually?
I'll be very grateful for any ideas and suggestions! <3
PS: I'm suprised he's getting away with that for weeks and months - sending 5000 messages a day, even tho not daily I believe. Isn't that API abuse violating Discord's ToS?
This is a very easy question to answer.
The answer is:
const Discord = require('discord.js');
const client = new Discord.Client();
let prefix = "!";
client.on('ready', () => {console.log('I am Ready')});
client.on('message', (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
var args = message.content.slice(prefix.length).split(/ +/);
var commands = args.shift().toLowerCase();
if (command === "ping") {
return message.channel.send('Pong!');
}
})
client.login('INSERT TOKEN HERE');
So the if statement at the start of code checks if the message starts with the prefix and if the message was sent by a bot.
Hope This helped.
Happy Coding!

Slack API remove bot from channel

I'd like to remove a slack bot from a channel using slack's API.
I've tried channels.kick but ofcourse, a bot is not a user so it can't be deleted that way. I haven't found any solutions so far on the interwet or on Slacks API documentation.
You are not correct. You can remove a bot user from a public channel or private channel using API methods just fine. I just tested it on a private channel to confirm.
So there must be another reason why this does not work for you. Please check if any of these reasons below apply to your case. Also, please provide the error message you are getting from the API, as that would greatly help to identify the reason.
Here are some potential reasons why kicking a bot user might not work for you:
wrong method: channels.kick only works for public channel, use groups.kick for private channels.
wrong token: bot tokens can not use the kick methods. You need to use a user access token to invoke that API method. (you would get the user_is_bot error)
trying to remove oneself: a user can not kick himself. (you would get the cant_kick_self error)
not using channel IDs: the kick methods require you to provide a channel ID, the name will not work. (you would get the channel_not_found error)
Based on your question I would assume you are getting the user_is_bot error, which let you to assume (incorrectly) that you can't kick a bot. In that case the solution would be to use a user token (not a bot token) to execute the method.

Leave a conversation with Skype Web SDK on page reload

We're building a web application using the Skype Web SDK (https://msdn.microsoft.com/en-us/skype/websdk/docs/skypewebsdk). We use both the audio and the IM capability to get connected to other parties.
Currently we're facing the following problem: If our application is in a conversation with another party (e. g. with a Skype for Business desktop client) and the user leaves or reloads the page, the other party doesn't get notified about the left user.
For audio conversations the result is the following: The other party is still in the call and the only indication of the leaving is that the other party can't hear anything.
For IM conversations the result is the following: If the other party sends an IM in this conversation it gets the notification that the message couldn't be delivered.
We've tried to leave the conversation before the unload of the page using the onbeforeunload event. The callback is executed both in IE 11 and Chrome, but only in Chrome the user actually leaves the conversation (tested with IM conversation since audio/video is not supported in Chrome).
window.onbeforeunload = function() {
// conversation is the conversation we're currently in
conversation.leave().then(function () {
client.conversationsManager.conversations.remove(conversation);
});
};
Since we rely on the audio capability we're not able to simply switch to Chrome only. Is there any way to ensure that the conversations are cleaned up on page reload/leave in Internet Explorer?
The problem with what you are trying to do is that the (on)beforeunload event does not wait around for asynchronous methods to complete so you are not guaranteed that leave() will execute nor the inner action to remove the conversation from the conversationsManager. I would suggest an approach similar to the following question - onbeforeunload confirmation screen customization or beforeunload
What you want to do is put the user into a state where the need to interact with a dialog which may (but also not guaranteed) give enough cycles to leave the conversation. In your case it might look something like the following:
window.onbeforeunload = function(e) {
// track if a conversation is live
if (_inActiveConversation) {
// conversation is the conversation we're currently in
conversation.leave().then(function () {
client.conversationsManager.conversations.remove(conversation);
});
var msg = 'Cleaning up active conversations...';
e.returnValue = msg;
return msg;
}
};
What you should also understand is that eventually the server side will remove that user from the conversation because the application is no longer processing incoming events. So the above is a best effort to clean up resources that will eventually be reclaimed.
You could also try to issuing a signOut request on the signInManager as that should allow the server to clean up resources related to that application on the server side.
window.onbeforeunload = function() {
...
_client.signInManager.signOut();
...
};

Wit.ai API converse doesn't respond with bookmarked action

I feel I must be doing something wrong in the API. I am following the weather example with a missing location. The story works fine.
However when I use the API over http using postman for testing purposes I cannot get it to raise the action after sending back the location from the user, It always returns a stop message. I think I must be not sending the correct context across or similar.
My understanding is as follows:
send across message 'I want to know the weather'
raises action from wit: 'Weather' (works correctly)
Respond with 'missingLocation'
wit replies with msg 'Which location do you want to know the weather for?' (works correctly)
I respond with 'Paris' in the message (no context all with same session)
wit replies with finding the entity 'Paris' but a 'stop' and no action. Here I would expect to get an action request again with everything I need to know this time. This is what happens when I use the story and test using the bot messenger.
Any ideas from anyone? I expect I need to respond with something more than just 'Paris' in the message
Thanks.
Note: the question was asked by "scruffjinks" on github before with no answer
https://github.com/wit-ai/wit/issues/301