Last active
December 10, 2015 18:08
-
-
Save christianchristensen/4472489 to your computer and use it in GitHub Desktop.
#golang appengine XMPP chat "room"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application: dodge-hrd | |
version: 1 | |
runtime: go | |
api_version: go1 | |
inbound_services: | |
- xmpp_message | |
handlers: | |
- url: /.* | |
script: _go_app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Very simple XMPP chat "room" using #golang on #appengine | |
// (similar to @partychat) | |
package dodge | |
import ( | |
"strings" | |
"appengine" | |
"appengine/xmpp" | |
) | |
// TODO move emails to invite state management stored in datastore | |
var emails = []string{ | |
"[email protected]", | |
"[email protected]", | |
} | |
func init() { | |
xmpp.Handle(handleChat) | |
} | |
func handleChat(c appengine.Context, m *xmpp.Message) { | |
// Remove resource from JID; pattern: node@domain/resource | |
// https://developers.google.com/appengine/docs/go/xmpp/overview#JIDs_and_Resources | |
sender := strings.Split(m.Sender, "/")[0] | |
reply := &xmpp.Message{ | |
To: emails, | |
Body: sender + ": " + m.Body, | |
} | |
err := reply.Send(c) | |
if err != nil { | |
c.Errorf("Sending reply: %v", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment