How to get channel updates with Telegram robot - telegram

I have searched over Telegram API and Bot API docs for days and it seems there is no direct way for a robot to get notified when there is a new update in a channel say a News channel, Sports channel, etc.
The only thing I came up with was:
A hook returns updates for channel only when the robot is an administrator member:
{
"update_id": 673009340,
"message": {
"message_id": 160,
"from": {
"id": 104911111,
"is_bot": false,
"first_name": "Jason",
"username": "jason",
"language_code": "en-US"
},
"chat": {
"id": -252946114,
"title": "jason",
"type": "group",
"all_members_are_administrators": true
},
"date": 1538468757,
"photo": [
{
"file_id": "AgADBAADFa4xG972mVHqJ-CSWQTFky4lnRoABNEgOrZpJU-OyDgFAAEC",
"file_size": 1795,
"width": 90,
"height": 90
},
{
"file_id": "AgADBAADFa4xG972mVHqJ-CSWQTFky4lnRoABB4OwmYVnYcOyTgFAAEC",
"file_size": 32559,
"width": 320,
"height": 320
},
{
"file_id": "AgADBAADFa4xG972mVHqJ-CSWQTFky4lnRoABIZfLEHYC_NVyjgFAAEC",
"file_size": 159833,
"width": 770,
"height": 770
}
]
}
}
I know that I cannot add a robot to a channel that is not owned by me. But, I can add my username jason to almost any channel. So, is there a way I get my jason_bot to be notified when there's a new update available for jason?

Bots cannot interact with channels unless they are one of the administrators of the channel.
If you want to receive updates from some one else's channels you must act as a client user not a bot. If you join the channel as a member, you can easily receive updates. However, you can check for updates of any public channel without being a member. First, you resolve the channel #username and get (id, access_hash) pair. Then, you can access all messages, and manually check against your database if there is something new.

Related

Telegram API Custom Emoji sending in message

As described in api doc for telegram - i can send custom emoji in message.
As update i receive somethings like this:
"text": "🌈",
"entities": [
{
"offset": 0,
"length": 2,
"type": "custom_emoji",
"custom_emoji_id": "5404870433939922908"
}
]
But when i'm sending same thing as message i see simple emoji:
{
"chat_id": 123,
"text": "🌈",
"entities": [
{
"offset": 0,
"length": 2,
"type": "custom_emoji",
"custom_emoji_id": "5404870433939922908"
}
]
}
Have no idea what i'm doing wrong. Help, please.
trying to send custom emoji in message through api.
AFAIK custom emoji are a premium feature and bots can't use them.

Transfer control with inline buttons in telegram (bots)

If you have a bot-generated in-line button in a chat, that inline button can be used to take you to a bot.
My question is - is the reverse possible?
Can the bot have an inline button (when directly communicating with it) and it can transfer control to a group where the user and bot are both present
Consider this scenario:
I have a bot that track country names. When added to a group it detects a country name and says “see information about the country”.
When you click the button, the bot takes you to a chat with it (changes wondows and moves you out) and then the bot displays information about the country.
The bot then has a “go back or cancel” inline button.
If you click that button, it should take you BACK to the originating group you came from. Is that possible?
Variation:
Can it move you back to the originating group automatically (without an inline button) but say based on some text you type?
All I got is you wanna to take back your users to their refer place right?
For example you have "Back" button in your channel. If user came from Channel A you want to detect that when it clicks on Back button you want to take it back to Channel A.
No it's not possible. Telegram bots can't track user activity like this. But Telegram do itself. For example if you visit some channels like this:
Channel A => First Post => Go to another channel (Channel B) => Then go to admin profile
If you click Back button triple time you will go to first step which in this case is Channel A
Bot if your bot is in one private group or private channel you can get the link of every message because Telegram added this feature here :
you can now copy links to messages in private groups and channels – just like you could with public messages.
So if user mention your bot's username on any message in private group/channel you can get the link of that message. Here is some example :
{
"ok": true,
"result": [{
"update_id": 954197936,
"message": {
"message_id": 188,
"from": {
"id": 223110107,
"is_bot": false,
"first_name": "Ğąme ",
"last_name": "Ǿver!",
"username": "GameO7er",
"language_code": "en"
},
"chat": {
"id": -1001241538300,
"title": "Game Over Test Group",
"type": "supergroup"
},
"date": 1576312634,
"reply_to_message": {
"message_id": 130,
"from": {
"id": 156878147,
"is_bot": false,
"first_name": "Carlos F",
"username": "#Carlos****",
"language_code": "en"
},
"chat": {
"id": -1001241538300,
"title": "Game Over Test Group",
"type": "supergroup"
},
"date": 1554783715,
"text": "Hello Game Over!"
},
"text": "#Go***bot",
"entities": [{
"offset": 0,
"length": 10,
"type": "mention"
}]
}
}]
}
The link of this message is:
https://t.me/c/1241538300/130
As you can see it will be generate from chat id
"chat": {
"id": -1001241538300,
"title": "Game Over Test Group",
"type": "supergroup"
},
remove -100 from -1001241538300 then you have 1241538300 and contact /c/message_id to end of it.
"date": 1576312634,
"reply_to_message": {
"message_id": 130,
"from": {
"id": 156878147,
"is_bot": false,
"first_name": "Carlos F",
"username": "#Carlos****",
"language_code": "en"
},
and you will have :
https://t.me/c/1241538300/130

Twilio Push Notifications: Get received status when sending using Passthrough API

I'm using the Twilio Notify Service to send push notifications to APN and FCM. We would like to switch to the passthrough API for situations where we send to a large number of users at once. Howerver, I'm not getting the to_binding field in the response, so have no idea how many succeeded or failed. When sending using identity, we get an array of identities.
Here is what we are sending:
twilio_client.notify.v1.services(ENV.fetch('TWILIO_NOTIFY_SERVICE')).notifications.create(
to_binding: params[:users],
body: params[:body],
title: params[:title],
data: {data: #data},
fcm: {
data: {
title: params[:title],
body: params[:body]
}
}
)
I get notifications on the devices, but this is what I get back:
{"body": "stuff", "sound": null, "sms": null, "alexa": null, "facebook_messenger": null, "tags": [], "title": "My Title", "segments": [], "ttl": 545435, "gcm": null, "account_sid": "account_id", "priority": "high", "apn": null, "data": {"data": {"a_thing": 995, "type": "My Type", "id": 4344}}, "sid": "myid", "action": null, "date_created": "2019-11-05T15:25:27Z", "service_sid": "service_id", "identities": [], "fcm": {"data": {"body": "stuff", "title": "My Title"}}}
in the example from the docs (https://www.twilio.com/docs/notify/api/notification-resource?code-sample=code-send-a-notification-to-bindings-in-the-request-1&code-language=Ruby&code-sdk-version=5.x), it looks like a toBindings field should come back.
Is there a way to get this working, or some way to fetch received receipt data after with the notification id?
It looks like as of now, this feature is not implemented, and is mentioned in their coming soon section along with iOS/Android SDKs

How to get TV info from Google Calendar Event?

I'm using the Google Calendar API to retrieve events for each of my favorite sports teams. An example calendar can be found here.
When you click on an event, it will show you information about the game, including the TV network it'll be played on, like this:
I'm making a home automation script to automatically detect events and turn on my TV etc., and change to the correct channel. My problem is that when I make a call to the API, the response doesn't include the TV information, each item looks like this:
{
"kind": "calendar#event",
"etag": "\"3014707204000000\"",
"id": "20171021T233000_2017102123",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=MjAxNzEwMjFUMjMzMDAwXzIwMTcxMDIxMjMgbmhsXzIzXyU1N2FzaGluZ3RvbislNDNhcGl0YWxzI3Nwb3J0c0B2",
"created": "2017-06-22T20:49:57.000Z",
"updated": "2017-10-07T05:20:02.000Z",
"summary": "Panthers # Capitals",
"creator": {
"email": "nhl_23_%57ashington+%43apitals#sports#group.v.calendar.google.com",
"displayName": "Washington Capitals",
"self": true
},
"organizer": {
"email": "nhl_23_%57ashington+%43apitals#sports#group.v.calendar.google.com",
"displayName": "Washington Capitals",
"self": true
},
"start": {
"dateTime": "2017-10-21T19:30:00-04:00"
},
"end": {
"dateTime": "2017-10-21T22:30:00-04:00"
},
"transparency": "transparent",
"visibility": "public",
"iCalUID": "20171021T233000_2017102123#google.com",
"sequence": 0,
"gadget": {
"iconLink": "https://calendar.google.com/googlecalendar/images/sport_hockey.png"
}
}
Does anyone know where this information is stored or if it's retrievable?
Thanks
maybe you can after getting that json reply download the "htmlLink" and parse the line that says TV:
It would be something like this(pseudo code):
Get JSON
Execute something like curl htmlLinkValue | awk '/TV:/' > result.txt
Read that file that will contain the networks.
Regards

Severely confused on how to properly use IdentityServer on my App

I may not properly understand how to properly implement IdentityServer4 with Xamarin.Auth.
Basically I'm using Xamarin.Auth for multiple cases
logging in with OAuth2 Vendors (MS/Google/FB)
logging in with self implemented OAuth2 (not used yet)
Speaking of case 1, I after committing login from the mobile app to Google/MS/FB I decide what to do further : go to the app's main page or register the user, by register storing the email as username and userId (the one that comes from the vendor) as password.
I've implemented IdentityServer4 with AspNetIdentity
From what I've read I need to implement Hybrid Authentication, but the issue here is that it features the need to use a WebView, in case 1 it isn't required anymore.
So basically I think I need to use Authorization Flow but trying to do any of them failed.
https://localhost:44348/connect/authorize?
client_id=XamClient&
client_secret=secret&response_type=code+id_token&
scope=openid&
redirect_uri=https%3A%2F%2Flocalhost%3A44348%2Fxamarincallback&
nonce=7a8ff1c107e345a8b055a8232ec15545&
code_challenge=8Kk9RQ8NX6w3YzL0eU7AWQurWnikb9NS9bVwa5lxhhE&
code_challenge_method=S256&state=d3a7b6a511da413395b2552fb194af2f
My issue here is that most of the examples feature an MVC view that gets this this url as redirectURL and then after the client commits a POST with his username and password then I'll get the AuthorizationCode, RefreshToken and IdentityToken.
I am really uncertain how to properly commit authentication in my case, what to use ?
I can only use
- Implicit
- Authorization Code - this is the only reasonable option for my first scenario ?
- Hybrid mode - tried all day to implement this realizing It's not possible ..
Anyways, after looking at the logs I've seen a sudden dubious redirect to the Account controller (asp login controller)
{
"name": "Microsoft.ApplicationInsights.Dev.Request",
"time": "2017-09-12T11:26:56.5388249Z",
"tags": {
"ai.location.ip": "127.0.0.1",
"ai.internal.nodeName": "EDWARD",
"ai.operation.id": "152eb716-4ff8951dec6a1ed1",
"ai.internal.sdkVersion": "aspnet5c:2.1.1",
"ai.application.ver": "1.0.0.0",
"ai.operation.name": "GET /connect/authorize",
"ai.cloud.roleInstance": "EDWARD"
},
"data": {
"baseType": "RequestData",
"baseData": {
"ver": 2,
"id": "|152eb716-4ff8951dec6a1ed1.",
"name": "GET /connect/authorize",
"duration": "00:00:00.1530713",
"success": true,
"responseCode": "302",
"url": "https://localhost:44348/connect/authorize?client_id=AnonymousCheckerClient&client_secret=secret&response_type=code+id_token&scope=openid&redirect_uri=https:%2F%2Flocalhost:44348%2Fxamarincallback&nonce=af1427d39dc2463697047a834169fdcf&code_challenge=UUi0a9cfhrcGvzddV9eh0Lc8cdr5WE-ZwSzwbY7ReNQ&code_challenge_method=S256&state=aafde38b65044c35b83a1fcb8771de2e",
"properties": {
"httpMethod": "GET",
"AspNetCoreEnvironment": "Development",
"DeveloperMode": "true"
}
}
}
},
{
"name": "Microsoft.ApplicationInsights.Dev.Message",
"time": "2017-09-12T11:26:56.6993438Z",
"tags": {
"ai.location.ip": "127.0.0.1",
"ai.operation.parentId": "|152eb717-4ff8951dec6a1ed1.",
"ai.internal.nodeName": "EDWARD",
"ai.operation.id": "152eb717-4ff8951dec6a1ed1",
"ai.internal.sdkVersion": "aspnet5c:2.1.1",
"ai.application.ver": "1.0.0.0",
"ai.operation.name": "GET /account/login",
"ai.cloud.roleInstance": "EDWARD"
},
"data": {
"baseType": "MessageData",
"baseData": {
"ver": 2,
"message": "Request starting HTTP/1.1 GET http://localhost:44348/account/login?returnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id%3DAnonymousCheckerClient%26client_secret%3Dsecret%26response_type%3Dcode%2520id_token%26scope%3Dopenid%26redirect_uri%3Dhttps%253A%252F%252Flocalhost%253A44348%252Fxamarincallback%26nonce%3Daf1427d39dc2463697047a834169fdcf%26code_challenge%3DUUi0a9cfhrcGvzddV9eh0Lc8cdr5WE-ZwSzwbY7ReNQ%26code_challenge_method%3DS256%26state%3Daafde38b65044c35b83a1fcb8771de2e",
"severityLevel": "Information",
"properties": {
"AspNetCoreEnvironment": "Development",
"Protocol": "HTTP/1.1",
"Host": "localhost:44348",
"QueryString": "?returnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id%3DAnonymousCheckerClient%26client_secret%3Dsecret%26response_type%3Dcode%2520id_token%26scope%3Dopenid%26redirect_uri%3Dhttps%253A%252F%252Flocalhost%253A44348%252Fxamarincallback%26nonce%3Daf1427d39dc2463697047a834169fdcf%26code_challenge%3DUUi0a9cfhrcGvzddV9eh0Lc8cdr5WE-ZwSzwbY7ReNQ%26code_challenge_method%3DS256%26state%3Daafde38b65044c35b83a1fcb8771de2e",
"Scheme": "http",
"Path": "/account/login",
"DeveloperMode": "true",
"CategoryName": "Microsoft.AspNetCore.Hosting.Internal.WebHost",
"Method": "GET"
}
}
}
}
Having analyzing the IdentityServer4 from Git this /authorize endpoint only accepts GET's and no user/pw.
Edit 01:
I've checked this resource and it confuses me with my scenario (1)...
https://developer.xamarin.com/guides/xamarin-forms/enterprise-application-patterns/authentication-and-authorization/

Resources