Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion appengine/xmpp/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ inbound_services:
- xmpp_presence
- xmpp_subscribe
- xmpp_error

18 changes: 17 additions & 1 deletion appengine/xmpp/xmpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,25 @@ def post(self):
# [END error]


# [START send-chat-to-user]
class SendChatHandler(webapp2.RequestHandler):
def post(self):
user_address = '[email protected]'
msg = ('Someone has sent you a gift on Example.com. '
'To view: http://example.com/gifts/')
status_code = xmpp.send_message(user_address, msg)
chat_message_sent = (status_code == xmpp.NO_ERROR)

if not chat_message_sent:
# Send an email message instead...
# [END send-chat-to-user]
pass
# [START send-chat-to-user]


# [START chat]
class XMPPHandler(webapp2.RequestHandler):
def post(self):
print "REQUEST POST IS %s " % self.request.POST
message = xmpp.Message(self.request.POST)
if message.body[0:5].lower() == 'hello':
message.reply("Greetings!")
Expand All @@ -83,4 +98,5 @@ def post(self):
('/_ah/xmpp/presence/available', PresenceHandler),
('/_ah/xmpp/error/', ErrorHandler),
('/send_presence', SendPresenceHandler),
('/send_chat', SendChatHandler),
])
5 changes: 5 additions & 0 deletions appengine/xmpp/xmpp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ def test_error(xmpp_mock, app):
'from': '[email protected]',
'stanza': 'hello world'
})


@mock.patch('xmpp.xmpp')
def test_send_chat(xmpp_mock, app):
app.post('/send_chat')