Transfer control with inline buttons in telegram (bots) - telegram

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

Related

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 make http post with the value of "Input.Date" from Outlook Adaptive Card?

I could http post only with Input.Number now, but Input.Date and Input.Text both receive 400 error.
I was planning to create a Microsoft Flow to receive some value from Outlook Adaptive Card Action.Http Post method, I followed some articles from internet show me how to do that, finally I get rid of the 401 error because it needs Authorisation header.
Okay, then I moved on to test http payload. The body couldn't be something like "body": "test", otherwise it will either gives me an 400 or even not shows adaptive card in email at all. After I learned that I have to use they officially suggested {{someId.value}} into "body".
I succeeded for the first time with Input.Number:
{
"type": "Input.Number",
"id": "test1",
"title": "New Input.Toggle",
"value": "",
"validation": null,
"placeholder": "Placeholder text",
"min": "0",
"max": "60"
}
Then outlook tells me it is successful and I did get the endpoint flow run and receive correct payload. And this is the "Action.Http" part:
"actions": [
{
"type": "Action.Http",
"title": "Say hello",
"method": "POST",
"url": "myflowhttptriggerurl",
"body": "{{nameInput.value}}",
"headers": [
{ "name": "Authorization", "value": "" }
]
}
]
Below is what get error:
After then, I tried with Input.Text and Input.Date, they all give me 400, below is payload, and don't worry for Action.Http, I change id each time when testing:
{
"type": "Input.Date",
"id": "h",
"title": "New Input.Toggle",
"value": "",
"validation": null
}
Text payload:
{
"type": "Input.Text",
"id": "newTask",
"isRequired": true,
"placeholder": "Enter a new task"
}
OK, first I would install the "Actionable Messages Debugger" into Microsoft Office to make it easier to understand if the contents of your card is correct.
It appears from the card you are doing it correct, what happening on your flow that is receiving the message?
You could always try send through a JSON object, so your body will be
"body": "{\"comment\":\"{{comment.value}}\"}"
Where comment is the id of your Input.Text as such:
{
"id": "comment",
"type": "Input.Text"
"isMultiline": true,
"placeholder": "Comments"
}

How to get channel updates with Telegram robot

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.

Dialogflow V2 Messenger Integration with Multiple Messages

I am trying to send to multiple messages within one Webhook call to Dialogflow, which shall be passed to Messenger. Right now my Webhook responds with a malfunctioning JSON body:
{
'fulfillmentText': "Text",
'fulfillmentMessages': [{
"platform": "facebook",
"text": [{
"text": "Text"
}]
}],
'source': "facebook"
}
When I test the Webhook via Messenger I see the is typing symbol, but never receive the Text message. While testing the same Webhook from the Dialogflow Console I get
Webhook execution successful
returned. I guess I am missing some JSON fields to tell Dialogflow in which format it has to send the JSON two the Messenger API. Anybody having any clues on how to solve this issue?
Edit:
My latest not working trial...
{
"fulfillmentText": "Hola!",
"fulfillmentMessages": [
{
"text": {
"text": [
"Title: this is a title"
]
},
"platform": "FACEBOOK"
},
{
"text": {
"text": [
"Title: this is a title"
]
},
"platform": "FACEBOOK"
}
]
}
If you're only sending text you only need to provide a string to the fulfillmentText and don't have to provide the fulfillmentMessages attribute.
If you do provide a fulfillmentMessages attribute with the target platform Dialogflow will send your payload to Facebook. In this case, where the payload is invalid, no message will actually be surfaced in Facebook. remove the fulfillmentMessages attribute of the response JSON and your bot should respond.
If you'd like to add a card to your response you can send the following response:
{
"fulfillmentMessages": [
{
"platform": "FACEBOOK",
"card": {
"title": "Title: this is a title",
"subtitle": "This is an subtitle. Text can include unicode characters including emoji 📱.",
"imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"buttons": [
{
"text": "This is a button",
"postback": "https://assistant.google.com/"
}
]
}
}
]
}
EDIT: If you want to send multiple messages you can do so by sending a response like this (this JSON will send two identical cards but you can change the message type (card/text/etc) based on this documentation):
{
"fulfillmentMessages": [
{
"platform": "FACEBOOK",
"card": {
"title": "Title: this is a title",
"subtitle": "This is an subtitle. Text can include unicode characters including emoji 📱.",
"imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"buttons": [
{
"text": "This is a button",
"postback": "https://assistant.google.com/"
}
]
}
},
{
"platform": "FACEBOOK",
"card": {
"title": "Title: this is a title",
"subtitle": "This is an subtitle. Text can include unicode characters including emoji 📱.",
"imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"buttons": [
{
"text": "This is a button",
"postback": "https://assistant.google.com/"
}
]
}
}
]
}
I mailed the Dialogflow support about this issue and it turns out that it is currently not possible to send multiple messages from a webhook.
Hi,
At this point, it's not possible to send sequential messages directly
from webhook. However, if you are using one of our one-click
integrations that support rich messages, you can invoke intents in
which multiple messages are defined from webhook through an event as
described at
https://dialogflow.com/docs/events#invoking_event_from_webhook.
Let me know if you have any questions.
Regards, Ankita from Dialogflow

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

Resources