Telethon Get Update When Contact Join Telegram - telethon

I'm using Telethon and i'm trying to implement a handler to listen events when a contact of mine joined to Telegram, but i don't find any documentation about that.
I see the docs of telethon updates events Telethon Doc - Update Events but i don't find a way to filter this specific event. Right now Telegram send a push notification when any of your contact join telegram and create a chat, so i think there should be an event that marks this
Can you help me?
Thanks!!

Listen to events.Raw and do a few checks on the event object that should look like this.
import asyncio
from telethon import TelegramClient, events
from telethon.tl.types import MessageActionContactSignUp, UpdateNewMessage
client = TelegramClient('YOUR_SESSION_NAME', 'YOUR_API_ID', 'YOUR_API_HASH')
client.start()
#events.register(events.Raw)
async def contact_join(event):
if isinstance(event, UpdateNewMessage) and isinstance(event.message.action, MessageActionContactSignUp):
print(event.message.from_id) #show the id of the contact joined
loop = asyncio.get_event_loop()
client.add_event_handler(check_join)
loop.run_forever()

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

Vertx Sockjs Eventbus handler authorization

Im building a social platform and just started on the websocket portion. I'm having trouble understanding where to hook my auth into the Vert.x SockJsHandler. I found a code example using "SockJsServer" via vertx.createSockJsServer here but it doesnt seem like that exists in current versions:
https://github.com/michalboska/codingbeer-vertx/blob/auth-experiment/src/main/java/ch/erni/beer/vertx/HTTPServerVerticle.java
The only hook Im aware of in current version is:
return SockJSHandler.create(vertx).bridge(options) {event ->
logger.info{ "socket event: ${event.type()}" }
event.complete(true)
}
I see event.socket().webUser() and .webSession() exists but am unclear how/where that would get set. So my question is, will I need to create an auth handler on the initial handshake only and if so, where? If a js client needs to receive notifications for say, a message from a specific chatroom they are a member 'chat123', should I register unique handlers for chat123, or somehow iterate over event.socket().webUser() for valid ids each time?
Most vert.x docs are offline with the new site migrating to vert.x 4 so infos a bit hard to find at the moment.

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.

General Workflow for bots

I've been tasked with setting up a bot to work with Yammer, as we are investigating using Yammer as an office communication tool.
Bots are essential to workflow, so they can notify users of important real-time events and can respond immediately to queries about system states even when not in the office without the need of complicated remote-desktop systems.
I've looked into Hubot, which has a Yammer adapter using a deprecated real-time API. However, this only reacts to posts made to public groups, and does not respond to private messages.
How would I start implementing something (which APIs to look at) to receive and send private messages in real-time? I feel this surely must be possible for a communication platform like Yammer (otherwise this defeats the point?), but I cannot find anything in the API documentation.
Thank you for your time.
Few changes in the hubot-yammer and yammer modules would make the adapters work with private groups as well.
Here is what I have done to make it work with private groups.
main.js:
I have modified the main.js of yammer module to pass the group id up front and modified it to call the messagesInGroup API of yammer to listen to private group messages.
RealTime.prototype.messages = function (g_id,cb) {
this.yam.messagesInGroup(g_id,function (e, body) {
Yammer.coffee:
Further modified Yammer.coffee script to call the yammer module with private group id.
class YammerRealtime extends EventEmitter under options
if options.access_token?
#g_id = options.g_id
## Yammer API call methods
listen: (callback) ->
#yammer.realtime.messages #g_id,(err, data) ->
With above changes hubot-yammer listens to private groups and responds back.

making GCM notifications configurable in applications

My question is
How to stop receiving notifications from GCM service with out using
GCMRegistar.unregistar(context).
Is there any method to stop receiving notifications.
I need this because I want to make GCM Push Notification feature configurable by the user if user sets for getting notification he will receive notification otherwise stops receiving notification with out unregistering device
Any links helps me a lot.
I do a similar thing with regards to my applications, if you get the paid version you get notifications, if you get the free version you don't get such updates.
I accomplished this by adding a field to the table where all my registration ID's are called status. When a notification push is done by my server it will only send to those registrations where the status is 'paid'.
So for your case I suggest adding the option to your application to stop receiving notifications. This method will perform a post to your server like follows:
Function updateNotificationStatus(boolean status)
{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://yourserver/update.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("status", status));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new
}
Handle these posts on your server and just update the status field in you table.
Hope this helps