Getting the user's "Last Seen" from a Telegram bot? - telegram-bot

When I chat with a telegram user, I can see for each user their "last seen" - when they last connected to Telegram (even if I haven't chatted with them for a while).
Is there a way to query for this information via the bot API? I haven't found a way to access it.

It's not possible with the Telegram Bot API.
But it's possible with Telegram API which allows you to build your own customized Telegram clients, and have other methods like read messages, or status (limited by the target users' privacy settings, of course).
After generate an hash to authenticate your API client on my telegram, you can use a library like Telegram-MTProto to call contacts.getStatuses which return an array of ContactStatus and know if user is online or offline.
const getStatuses = async () => {
const statuses = await telegram('contacts.getStatuses', {})
// Check online status
if(statuses[0].status._ === 'userStatusOnline')
// Online
}

That's currently not possible with the Telegram Bot API.

In plus messenger , using bot login , relative last seen is shown.
Maybe you could ask them in their Official support group: https://t.me/plusmsgrchat (I'm blocked)

https://core.telegram.org/bots#4-how-are-bots-different-from-humans
Bots have no online status and no last seen timestamps, the interface shows the label ‘bot’ instead.

Related

Sending a message to whatsapp groups through twilio with asp.net core

I am trying to use whatsapp business api for my application with twilio. I already have read the documentation of whatsapp business api. My question is, can we use twilio to send the messages to different whatsapp group based on id.
For example, If I have 3 groups such as Students, Professors, Assistants and based on each different group I want to send a specific message such as Hi to Students, Hello to Professors and Hey to Assistants.
What I know till now that Whatsapp differentiate everything with specific id, for instance, chat.whatsapp.com/DeUzzel9O13231
I also have worked with the twilio and whatsapp api where you can send a message from your twilio number to your whatsapp number like below
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
class Program
{
static void Main(string[] args)
{
// Find your Account Sid and Token at twilio.com/console
// DANGER! This is insecure. See http://twil.io/secure
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const string authToken = "your_auth_token";
TwilioClient.Init(accountSid, authToken);
var message = MessageResource.Create(
body: "Join Earth's mightiest heroes. Like Kevin Bacon.",
from: new Twilio.Types.PhoneNumber("+15017122661"),
to: new Twilio.Types.PhoneNumber("+15558675310")
);
Console.WriteLine(message.Sid);
}
}
The code above is only for sending a message to a specific number. Can I do the same thing with the groups? If yes, How? Is there any documentation for that?
Thanks.
Doesn't look like a supported feature just yet.
"Can I send messages to WhatsApp groups or manage groups?
Currently, our API does not support messaging with or managing
WhatsApp groups. We expect to add support for groups in the future."
Source: https://www.twilio.com/docs/sms/whatsapp/best-practices-and-faqs#frequently-asked-questions-on-whatsapp-integrations

Google GMail callback when someone reply to thread

I'm using Google GMail Api. All works fine with synchronous requests. However I would like to get notified when someone reply to given thread_id to a callback somehow.
I found this article https://developers.google.com/gmail/api/guides/push?hl=pl about push notifications and it's great but still I don't know how to setup Observer I have described above.
I'm using PHP btw, but I just need concept how it works and how I can setup that kind of communication between API and app.
There is currently no available API that detects/observes (something that behaves like a callback) if there is a reply for a specific thread_id.
You'll have to do the checking yourself, doing some polling (with users.threads.get) to see if there is a reply. Similar to what the OP was doing in this post (emphasis mine):
We have a web application that makes use of the Gmail API to automate certain emails on our users' behalf. When the application sends an email, it stores the threadId returned by the Gmail API. It then uses this threadId to poll the Gmail users.threads.get API, looking for replies. When a reply is detected, it pauses future emails.
You can use the Push notifications provided by Gmail API. The document is available here:
https://developers.google.com/gmail/api/guides/push?hl=pl#python
It's pretty much straight forward. Create a topic, then create a push subscription for the topic. It requires a webhook pointing to your web app. Grant necessary permission to the Gmail service account as mentioned in the document.
Use the below Python code to get notified:
request = {
'labelIds': ['INBOX'],
'topicName': 'projects/myproject/topics/mytopic'
}
gmail.users().watch(userId='me', body=request).execute()
We get a response with HistoryId. Tracking all the messages since the HistoryId can be done like this:
history = (service.users().history().list(userId=user_id, startHistoryId=start_history_id)
I found the below video helpful:
https://www.youtube.com/watch?v=wjHp9_NAEJo

How to receive messages in group chats using telegram bot api

My telegram bot receives messages sent by user to my bot in private chats but not receives messages sent by users in group chats. Any options/api for getting group chat messages also,.
Talk to #botfather and disable the privacy mode.
Sequence within a BotFather chat:
You: /setprivacy
BotFather: Choose a bot to change group messages settings.
You: #your_name_bot
BotFather: 'Enable' - your bot will only receive messages that either start with the '/' symbol or mention the bot by username.
'Disable' - your bot will receive all messages that people send to groups.
Current status is: ENABLED
You: Disable
BotFather: Success! The new status is: DISABLED. /help
By default A Bot will receive only messages addressed to it by any user directly via posting by /command#YourBot any message you send.
After that it vill be available via getUpdates API call.
In browser it will be:
https://api.telegram.org/botToken/getupdates
Find the related message in output JSON and grab chatId. It will allow you to answer back with:
https://api.telegram.org/botToken/sendmessage?chat_id=123456788&text=My Answer
Make your bot by admin in group.
You can access all avaliable settings from all of your bots by sending /mybots to Botfather. Choose the bot, then Bot Settings and Group Privacy. If its disable (default), you can tap on Turn off.
Now its possible to receive the chat history using GetUpdates. This can be done via HTTP API or the frameworks. For example, in C# (.NET Core) like this:
var bot = new TelegramBotClient(ApiToken);
var updates = bot.GetUpdatesAsync().Result;
foreach(var update in updates) {
Console.WriteLine($"{update.ChannelPost.Date} {update.ChannelPost.Text}");
}
But keep in mind that this feature has some kind of perfect forward secrecy implemented. So you only get messages that were send after group privacy is disabled. As a result, the GetUpdates result is empty until some post was made.
if you added your bot before disable the privacy mode, you should remove the bot from the group and add it again

Can I send Instagram Direct messages programmatically through the API? Is there a limit?

I want to build an Instagram Hashtag Gallery (an image/video gallery that will scrape the image/video media of all public instagrams with a specific hashtag)- that part is easy enough and very common. However, given the uncertainties involved in receiving ALL messages when searching for a hashtag, I also want to send a confirmation message to users after their submission has been received. The best way would seem to be through an Instagram Direct private message. I cannot find anything about whether this is possible and if there are limits to the number of Instagram Direct messages my app can send.
Is this possible?
As far as I can tell, it's not possible.
With the Instagram API console, you can check for the supported methods: API Console
Sure it is, you just need to use the instagram private API.

soundcloud authentication for server-side code (no app!)

I would like my server-side code to upload tracks to soundcloud in its own name, then later it will retrieve comments, favourites and listener counts. I do not want to do this on behalf of an app user - for there is no app! Previous questions here on stackoverflow§ (there is no "me too" button) and the API docs seem to suggest I cannot do this. Am I correct?
§ Can track belong to the application and not individual users?
This is called "Authenticating without the SoundCloud Connect Screen" in the API docs:
http://developers.soundcloud.com/docs/api/guide#user-credentials
An "app" in this case is a program that wants to access the Soundcloud API. You register them here:
http://soundcloud.com/you/apps/
Normally you would make a unique username, and register the app to that user. Then, the code logs in as that user to authenticate.