1616
1717import logging
1818
19- # [START xmpp-imports]
2019from google .appengine .api import xmpp
2120
22- # [END xmpp-imports]
2321import mock
2422import webapp2
2523
2927
3028class SubscribeHandler (webapp2 .RequestHandler ):
3129 def post (self ):
32- # [START track]
3330 # Split the bare XMPP address (e.g., user@gmail.com)
3431 # from the resource (e.g., gmail), and then add the
3532 # address to the roster.
3633 sender = self .request .get ("from" ).split ("/" )[0 ]
3734 roster .add_contact (sender )
38- # [END track]
3935
4036
4137class PresenceHandler (webapp2 .RequestHandler ):
4238 def post (self ):
43- # [START presence]
4439 # Split the bare XMPP address (e.g., user@gmail.com)
4540 # from the resource (e.g., gmail), and then add the
4641 # address to the roster.
@@ -50,33 +45,27 @@ def post(self):
5045 status = self .request .get ("status" ),
5146 presence_show = self .request .get ("show" ),
5247 )
53- # [END presence]
5448
5549
5650class SendPresenceHandler (webapp2 .RequestHandler ):
5751 def post (self ):
58- # [START send-presence]
5952 jid = self .request .get ("jid" )
6053 xmpp .send_presence (jid , status = "My app's status" )
61- # [END send-presence]
6254
6355
6456class ErrorHandler (webapp2 .RequestHandler ):
6557 def post (self ):
66- # [START error]
6758 # In the handler for _ah/xmpp/error
6859 # Log an error
6960 error_sender = self .request .get ("from" )
7061 error_stanza = self .request .get ("stanza" )
7162 logging .error (
7263 "XMPP error received from {} ({})" .format (error_sender , error_stanza )
7364 )
74- # [END error]
7565
7666
7767class SendChatHandler (webapp2 .RequestHandler ):
7868 def post (self ):
79- # [START send-chat-to-user]
8069 user_address = "example@gmail.com"
8170 msg = (
8271 "Someone has sent you a gift on Example.com. "
@@ -87,21 +76,16 @@ def post(self):
8776
8877 if not chat_message_sent :
8978 # Send an email message instead...
90- # [END send-chat-to-user]
9179 pass
9280
9381
94- # [START chat]
9582class XMPPHandler (webapp2 .RequestHandler ):
9683 def post (self ):
9784 message = xmpp .Message (self .request .POST )
9885 if message .body [0 :5 ].lower () == "hello" :
9986 message .reply ("Greetings!" )
10087
10188
102- # [END chat]
103-
104-
10589app = webapp2 .WSGIApplication (
10690 [
10791 ("/_ah/xmpp/message/chat/" , XMPPHandler ),
0 commit comments