Skip to content

Commit

Permalink
Add Missing XMPP Snippet + Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Prin committed Apr 28, 2016
1 parent 502ef25 commit 82f7d91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
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 = 'example@gmail.com'
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': 'sender@example.com',
'stanza': 'hello world'
})


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

0 comments on commit 82f7d91

Please sign in to comment.