Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Missing XMPP Snippet #306

Merged
merged 2 commits into from
Apr 28, 2016
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')