I've coded a Telegram bot (python-telegram-bot) and I would like to know if there's a way to open an app from the bot.
To be more accurate, the bot searches torrent links and the original idea was to send that links directly to qBitTorrent in the user's computer but unfortunately I'm stuck in that step, so for the moment I though about give the user the magnet link so it can be pasted in the qBitTorrent app. The thing is that it would great to automaticly open the app from the bot.
Thanks in advance!
A bot can't open an external app
I've also stuck on this problem. I've tried to open another app via URI, for example:
things://add?title=My%20new%20task
The example above shows my try to open the macOS application called Things.
The main answer is: Telegram doesn't allow to open external applications from bot and doesn't allow use any protocol in URI, except for http and tg.
I think, you can use 3rd-party (or your one) service, which will redirect you on any page that you will ask. Your URL may be a URI to your app: your mobile/PC browser can redirect you directly to the app.
Generally speaking, you're right: one Android app is able to start another app.
However, in this case, this is not your app, we're talking about, but you want another app (Telegram) to open another app. So you have to rely on what that app (Telegram) provides you with their API.
You can have a look at Telegram's bot API at https://core.telegram.org/bots/api There is no method to execute commands or open another app. So it will not be possible for you to open another app with your Telegram bot.
I was also trying to do this, but that was not possible. But as workaround you can make a simple site that opens the app and make Telegram open that.
Related
I have a Python script that works great with 'telegram bot'. I want to send the user a welcome message on start of the app.
Hopefuly someone here can direct me how to do this.
Thanks in advance.
I have tried using the send_text function in several places on the script with no luck.
This is not possible, as the Bot API does not send an update when the user opens the app.
Ok, no code here, more trying to get some directions.
I'm working on my home automation using tuya objects. Till now I was able to create a websocket (using python websockets and asyncio) that gets a message and turn on my devices. I created a flask website to configure passwords, keys etc. Now what I'm trying to achieve is using a NFC tag(scanned by my phone) call the websocket sending a message. I bought some NFC tags, got a an android app called NFC Tools to record data into the NFC tag.
Problem is NFC tools doesnt give me too many options I can add text, and URLs but I dont know how to call my websocket from there. Can I call it using its URL like ws://something.go? Can I make the phone not open a browser when I scam the tag? Should I create a page on flask for that and put the page address?
Anyway, I'm kind of lost. Can you guys point me in the right direction?
The right direction is to write your own NFC app for your phone.
In OS has a basic limited (fallback) idea of how to process the different type of Ndef record types, but it mostly relies on App's registering that they are capable for processing a certain record type.
So the OS can process various URL formats and open a web browser BUT ws: is not a standard URI as defined by the Ndef specs.
Thus the OS has nothing to processes it with.
To solve this you would best to make up your own mimeType string and create an App that registers that it can process this mimeType (Android docs on this, iOS has something similar). Then when you scan your custom Tag and the OS know what App can process this Tag, you app then reads the data and processes it accordingly and open the websocket request itself.
End up creating a get route on flask and using NFC Tools Pro with http get to access it. The route just send a message to my websocket and turn on or off my devices. Thx Andrew for the tip I will have that in mind if this goes anywhere far from a personal project.
TLDR: I have a slack app for managing private channels in its development workspace and tokens for it that inherit my user privileges. How can someone else in the same workspace obtain tokens for this app that inherit their user privileges instead?
Ok, so the background of this is: i need to manage the membership of a bunch of private channels based on some more or less complicated ldap-related conditions. For this, i wanted to write a simple Python program that got the membership of the channels in question, did its ldap magic to figure out who should be where, and then make it so.
I have implemented this and all works fine so far. The issue now is that i (that is my slack user) cannot be in all of these channels for privacy reasons. The API and Bot tokens i have obtained inherit all of my own user privileges. That means i can neither see nor administrate the channels that i'm not a part of.
Based on what i've read in the documentation of the Slack API, there's a way to have another user go through the OAuth process for the app that i created to get the tokens, get their own tokens, and use them with the Python program that i wrote. That would be fine, but i can't figure out how to do this.
Noone else has access to the app directly. The documentation makes it seem like i need to give people a specially formatted link (the "Add to Slack Button") that they can click on to get taken through the process. But that seems to require a "redirect URL". I'm not sure what this is and the documentation isn't very clear on it, but it seems they are assuming that the app is running on a server somewhere and will need to answer requests from Slack or something. That's not the case. It's a fairly simple Python script, not some always-up cloud app that will be responding to Slack Events.
So it feels like i'm missing something. Either i have some fundamental misconception about how this is supposed to work, or there is a simple way for someone else to get a token like that and i'm not seeing it.
Yes. If you want other users to authenticate your app (e.g. generate tokens so your app can perform tasks on the users behalf) you need to create an installation routine using Ouath 2.0. That installation routine is a small web app that has the "Add to Slack" button, a HTML interface and is able to run through the Oauth 2.0 process. That web app needs to run on a public web server.
For development purpose that web server can also run on your local dev machine with a VPN tunnel to the public Internet. Slack recommends using the VPN service ngrok for that purpose.
I am doing a Spotipy script that I want to automize and put it on a server.
By "automize" I mean that for the authentification I don't want to have to copy/paste the open URL (I'm using Authorization Code Flow), is it possible? Or maybe there is a way to catch that opened URL and paste it automatically to the program on the server?
Thank you.
If I understand you correctly:
You can use Flask: http://flask.pocoo.org/, which is a microframework for serving applications (your scripts).
This way, every time you go to URL on your browser (Flask default is localhost:5000), authorization code will run automatically, and you can then be redirected to your served pages, as long as you have templates (html) for them.
Here's an example of how you can implement one app:
https://github.com/datademofun/spotify-flask
And here's a Walkthrough of Authorization Code Flow using Flask and Python, with the Spotify API:
https://github.com/drshrey/spotify-flask-auth-example
I'm using Spotipy to get some spotify data from an authorized user but I can't understand how to authorize my account.
Am I correct in thinking that a server is required that hosts something at http://www.myapp.com/callback ? What needs to be returned? Maybe I'm completely missing something here... I'm very confused by the whole required redirect URI thing...
I am trying to make a program, without website, so how should I handle authorization? What exactly should the redirect URI do?
Thanks
Edit:
Using http://localhost:8888/callback as my redirect URI now and that works. I'm not even sure why since nothing is running on that port.
Disclaimer: I know nothing about Spotify's API. But I have worked with similar APIs in the past (or even designed them). What I assume is that they use some kind of OpenID/OAuth authorization mechanism.
The very nature of these APIs is that they work through the browser! The idea is that MyApp doesn't have your actual Spotify credentials, but instead some signed token it can use.
To communicate this token to the MyApp, there are the server-callbacks, outlined in your question. Because all the browser can do is to redirect to a special URL you provide, with some info added.
So there are conceptually two ways to deal with this:
the easy, server-based one: you in fact register a myapp.com. When your app tries to authorize with spotify, it first creates a unique resource (myapp.com/authrequests/HASH-NUMBER), and communicates this as callback. Then it goes through the motions of making spotify authorize it, and once these are finished, there will have been a call to myapp.com/authrequests/HASH-NUMBER/ADDITIONAL-INFO. So while your app is waiting for this to happen, it has to poll (or open a websocket and listen to that) myapp.com. Complicated? Wait, it gets better!
the harder, OS-dependent one: you write an application that registers itself as protocol-provider with your browsers. E.g. my company does that with the protocol "ableton". Thus we can make the browser generate "ableton://AUTHORIZATION-REQUEST-RESULT" URLs which will then be communicated through Browser and OS to the running application, and thus you receive the necessary secret.
HTH