Skip to content

Commit fac6fd5

Browse files
author
Bill Prin
committed
Add Missing XMPP Snippet
1 parent 502ef25 commit fac6fd5

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

appengine/xmpp/app.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ inbound_services:
1313
- xmpp_presence
1414
- xmpp_subscribe
1515
- xmpp_error
16-

appengine/xmpp/xmpp.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,25 @@ def post(self):
6868
# [END error]
6969

7070

71+
# [START send-chat-to-user]
72+
class SendChatHandler(webapp2.RequestHandler):
73+
def post(self):
74+
user_address = 'example@gmail.com'
75+
msg = ('Someone has sent you a gift on Example.com. '
76+
'To view: http://example.com/gifts/')
77+
status_code = xmpp.send_message(user_address, msg)
78+
chat_message_sent = (status_code == xmpp.NO_ERROR)
79+
80+
if not chat_message_sent:
81+
# Send an email message instead...
82+
# [END send-chat-to-user]
83+
pass
84+
# [START send-chat-to-user]
85+
86+
7187
# [START chat]
7288
class XMPPHandler(webapp2.RequestHandler):
7389
def post(self):
74-
print "REQUEST POST IS %s " % self.request.POST
7590
message = xmpp.Message(self.request.POST)
7691
if message.body[0:5].lower() == 'hello':
7792
message.reply("Greetings!")
@@ -83,4 +98,5 @@ def post(self):
8398
('/_ah/xmpp/presence/available', PresenceHandler),
8499
('/_ah/xmpp/error/', ErrorHandler),
85100
('/send_presence', SendPresenceHandler),
101+
('/send_chat', SendChatHandler),
86102
])

appengine/xmpp/xmpp_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@ def test_error(xmpp_mock, app):
5858
'from': 'sender@example.com',
5959
'stanza': 'hello world'
6060
})
61+
62+
63+
@mock.patch('xmpp.xmpp')
64+
def test_send_chat(xmpp_mock, app):
65+
app.post('/send_chat')

0 commit comments

Comments
 (0)