XMPPPY have function to manage invitation in client side? - python

I'm coding by python about Gtalk I use XMPPPY.
But I can chat with GTalk client but the problem is I can't accept invitation.
Is XMPPY can do ?

Looks like you want to "authorize" the request. I'm assuming you've received the request at the client. In the roster class (xmpp.roster) there is an "Authorize" method. It sends the "subscribed" packet to accept the roster request. This is what the method looks like:
def Authorize(self,jid):
""" Authorise JID 'jid'. Works only if these JID requested auth previously. """
self._owner.send(Presence(jid,'subscribed'))
Wait, that may not be what you're asking at all. Are you trying to process a chat or a roster request? Take a look at the example (small) client they have called xtalk.py. I think you're interested in the xmpp_message method.

Related

How to send a message from my name (my account, not the bot) in Telegram using Python?

I already have the main script. Now I only need the method that will send a certaing message from my account (my name) to another person automatically. Is it possible to send messages that way?
You would have to use the Telegram Database Library, which is a set of APIs you can use to control your user's actions via HTTP requests. Then you'll use the sendMessage class to send a message as yourself. The Get Started page pretty much has everything you need for your project.
Source: https://core.telegram.org/#tdlib-build-your-own-telegram

How do I "say" to the Telegram API that I got their webhook request successfully?

I'm adapting my Telegram bot to accept webhooks requests instead of doing constant polling, so I read the Telegram API documentation about the setWebhook method.
I'm using Python's micro-framework Flask to create my web application that receives the request.
Somewhere in the documentation it says "In case of an unsuccessful request, we will give up after a reasonable amount of attempts.". What does it mean? Do I have to return something specific in my #app.route decorator so the API understand I got what I wanted? I don't have much knowledge on web application so I have no idea how to say "hey I got what you sent".
It means if it fails to send the update (for example if your webhook is down). You don't have to return anything, you just need your webhook to be active by the time.
The Webhook approach allows Telegram to push the messages to your backend.
The Webhook should normally always be online, but if it is down the message (on Telegram side) is queued for a while.
This works nicely when your Flask app needs some time, for example, to startup.
Note the message is delivered once: if the Webhook fails (backend error) and return an error text or http status code (403) the message is consumed and will not be re-sent.

Flask: How can I store the connection details of clients [Inside NAT], so I can POST them a webhook later?

I want to make a /subscribe endpoint that will add the client to a list that will be notified with a webhook when an event happens. How can I get the data from flask needed to connect to the client later so I can then send a POST in requests later?
You can not store the connection details.
There is nothing called CONNECTION. It is just an HTTP request from one server to the other.
All HTTP requests are just messages that you (Browser or a server) sends to another server asking for something like "Can I view your website?" or "Can you send me this data?" etc.,
Possible solution for you:
I have worked on webhooks for one of your products in our company and the best way to give the ability to create a webhook to your client is, asking for their endpoint.
What I did:
I ask the client for their endpoint so that I can call it whenever there is an event.
Ask them to create and share a secret_key so that no one else can call that endpoint other than you.
Call that endpoint using their secret_key whenever there is an event.
Above is just an outline of how it is done (Or at least how I did it).

Python POST request gives unknown result

So I'm really out of my element with RESTful stuff. I'm trying to make a thing on that subscribes to an action/webhook(?) on twitch.tv so that if someone goes live, it knows.
I want to use this webhook here:
https://dev.twitch.tv/docs/api/webhooks-reference/#topic-stream-changed
I made a Flask server in server.py:
app = Flask(__name__)
#app.route('/', methods=['POST'])
def result():
print(request.data)
return 'Received'
and the POST I make is over here in notify.py:
import requests
r = requests.post("https://api.twitch.tv/helix/webhooks/hub", headers={'Client-ID': client_id}, data={"hub.callback": "http://127.0.0.1:5000/","hub.mode":"subscribe",'hub.topic':"https://api.twitch.tv/helix/streams?user_id=XXXXXX"})
Running my code shows nothing on the server, not even Received so I guess I'm doing something wrong.
if I do a GET, on
request = requests.get('https://api.twitch.tv/helix/streams?user_id=xxxxxx', headers={'Client-ID': client_id})
the result is b ' '
and I have no idea what that means
in notifiy.py, putting a print(r) returns <Response [202]> but I think I want a [200]
I assume my server needs to be reachable by Twitch to see it but I'm not sure.
Any help is appreciated!
Final EDIT... I have created a proof of concept
You're POSTing "hub.callback": "http://127.0.0.1:5000/". That URL is only accessible on your machine.
This is supposed to be a URL which is accessible from the Twitch infrastructure. If you can't register a domain, then you could use something like ngrok to get a valid URI which routes back to your Flask development server for testing.
Once you have sent the POST request, you can get the webhook subscriptions to confirm the post request worked. This is also possible using curl, with the commands included to the right of this documentation.
Assuming you see valid subscriptions there, then the endpoint you provide as hub.callback should receive a hit from Twitch...
when a stream changes; e.g., stream goes online or offline, the stream title changes, or the game changes.
Within the route you'd then do some logic to deal with the result of that request.
Update re comments
You may wish to try updating hub.lease_seconds: (here)
Number of seconds until the subscription expires. Default: 0. Maximum: 864000.
The default (0) allows you to test the subscription-creation workflow without creating any subscriptions (since they expire immediately). After testing, to actually create subscriptions, you must specify a larger value.
This belongs in the dictionary passed as the data argument to requests.post in notify.py:

How can I get a response with XMPP client in Python

I'm using XMPP in Python, and I can send messages, but how can I receive?
I must register a handler and process:
def messageCB(sess,mess):
print 'MESSAGE'*100
nick=mess.getFrom().getResource()
text=mess.getBody()
#print mess,nick
print text
client.RegisterHandler('message',messageCB)
while 1:
client.Process(1)
Good post. I notice this code snippet is also in the logger example in xmpppy sourceforge website.
I wonder if it is possible to reply to incoming messages. The code above only receives and the nickname resource ID does not indicate who the sender is (in terms of JID format, user#server) unless xmpppy can translate that appropriately. So how might one take the received message nd "echo" it back to the sender? Or is that not easily possible with the xmpppy library and need to find a different XMPP library?

Categories