{"action":"created","issue":{"url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/596","repository_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/596/labels{/name}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/596/comments","events_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/596/events","html_url":"https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596","id":184110113,"number":596,"title":"adding new xmpp wikibot example","user":{"login":"mogar1980","id":20994574,"avatar_url":"https://avatars.githubusercontent.com/u/20994574?v=3","gravatar_id":"","url":"https://api.github.com/users/mogar1980","html_url":"https://github.com/mogar1980","followers_url":"https://api.github.com/users/mogar1980/followers","following_url":"https://api.github.com/users/mogar1980/following{/other_user}","gists_url":"https://api.github.com/users/mogar1980/gists{/gist_id}","starred_url":"https://api.github.com/users/mogar1980/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mogar1980/subscriptions","organizations_url":"https://api.github.com/users/mogar1980/orgs","repos_url":"https://api.github.com/users/mogar1980/repos","events_url":"https://api.github.com/users/mogar1980/events{/privacy}","received_events_url":"https://api.github.com/users/mogar1980/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/labels/cla:%20yes","name":"cla: yes","color":"009800"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-10-20T00:49:55Z","updated_at":"2016-10-25T21:56:23Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/596","html_url":"https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596","diff_url":"https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596.diff","patch_url":"https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596.patch"},"body":"jerjou@ could you review this example? Feel free to move to new directory if necessary."},"comment":{"url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/comments/256188682","html_url":"https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#issuecomment-256188682","issue_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/596","id":256188682,"user":{"login":"mogar1980","id":20994574,"avatar_url":"https://avatars.githubusercontent.com/u/20994574?v=3","gravatar_id":"","url":"https://api.github.com/users/mogar1980","html_url":"https://github.com/mogar1980","followers_url":"https://api.github.com/users/mogar1980/followers","following_url":"https://api.github.com/users/mogar1980/following{/other_user}","gists_url":"https://api.github.com/users/mogar1980/gists{/gist_id}","starred_url":"https://api.github.com/users/mogar1980/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mogar1980/subscriptions","organizations_url":"https://api.github.com/users/mogar1980/orgs","repos_url":"https://api.github.com/users/mogar1980/repos","events_url":"https://api.github.com/users/mogar1980/events{/privacy}","received_events_url":"https://api.github.com/users/mogar1980/received_events","type":"User","site_admin":false},"created_at":"2016-10-25T21:56:23Z","updated_at":"2016-10-25T21:56:23Z","body":"I can take it over and likely finish it up in the next week or so. Do you\nmind if I switch it to GAE Flex? It'll make setup for the users much easier.\n\nOn Thu, Oct 20, 2016 at 1:02 PM Morgan Hallmon <morgan.hallmon@gmail.com>\nwrote:\n\n> Would one of you guys be able to take this over? I'm not sure that I have\n> time to address all your comments in time as I need to shift to another big\n> deliverable due next week. As there will be few users (max ~100) who\n> actually try to migrate to an XMPP server, I'm less worried about editorial\n> control over this sample. Feel free to make whatever changes you like as\n> long as:\n>\n>    1. The general functionality is retained (sending messages via GET and\n>    responding to incoming chats with a Wikipedia page on the subject)\n>    2. The setup in the README is easy to understand and follow.\n>\n> Please let me know.\n>\n> Thanks!\n> Morgan\n>\n> On Thu, Oct 20, 2016 at 10:44 AM, Jerjou <notifications@github.com> wrote:\n>\n> *@jerjou* commented on this pull request.\n> ------------------------------\n>\n> In appengine/standard/xmpp_wikibot/README.md\n> <https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#pullrequestreview-5112761>\n> :\n>\n> > @@ -0,0 +1,62 @@\n> +# Wikibot example that can be run on Google Compute Engine\n> +\n> +This sample shows how to use the [SleekXMPP](http://sleekxmpp.com/index.html)\n> +client and [Flask](http://flask.pocoo.org/) to build a simple chatbot that can\n> +be run on [Google Compute Engine](https://cloud.google.com/compute/). The\n> +chatbot does two things:\n> +    1. Sends messages to XMPP users via http get:\n>\n> The formatting gets messed up here. You can see what it'll look like by\n> clicking the \"View\" button in this review.\n>\n> It should look like:\n>\n> ...chatbot does two things:\n>\n> 1. Sends messages to XMPP users via http get:\n>\n>     The server is running on port 5000.\n>\n>     If running on a virtual machine, use:\n>\n>     http://<MACHINE IP>:5000/send_message?recipient=<RECIPIENT ADDRESS>&message=<MSG>\n>\n>     If running locally, use:\n>\n>     http://localhost:5000/send_message?recipient=<RECIPIENT ADDRESS>&message=<MSG>\n>\n> 1. Responds to incoming ...\n>\n> ie:\n>\n>    1. You shouldn't indent the first line\n>    2. Subsequent lines shouldn't be indented so much. Otherwise, they\n>    become code blocks.\n>    3. If you want something on a new line, you have to separate it by a\n>    blank line.\n>    4. For numbered lists, the actual number you use doesn't matter ;)\n>    5. See here <https://guides.github.com/features/mastering-markdown/>\n>    for a markdown tutorial\n>\n> ------------------------------\n>\n> In appengine/standard/xmpp_wikibot/README.md\n> <https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#pullrequestreview-5112761>\n> :\n>\n> > @@ -0,0 +1,62 @@\n> +# Wikibot example that can be run on Google Compute Engine\n> +\n> +This sample shows how to use the [SleekXMPP](http://sleekxmpp.com/index.html)\n> +client and [Flask](http://flask.pocoo.org/) to build a simple chatbot that can\n> +be run on [Google Compute Engine](https://cloud.google.com/compute/). The\n> +chatbot does two things:\n> +    1. Sends messages to XMPP users via http get:\n> +       The server is running on port 5000\n> +       if running on virtual machine use:\n> +       http://<MACHINE IP>:5000/send_message?recipient=<RECIPIENT ADDRESS>&message=<MSG>\n> +\n> +       If running locally use:\n> +       http://localhost:5000/send_message?recipient=<RECIPIENT ADDRESS>&message=<MSG>\n> +\n> +    2. Responds to incoming messages with a wikipedia page on the topic:\n>\n> capital-W-Wikipedia\n> ------------------------------\n>\n> In appengine/standard/xmpp_wikibot/README.md\n> <https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#pullrequestreview-5112761>\n> :\n>\n> > +chatbot does two things:\n> +    1. Sends messages to XMPP users via http get:\n> +       The server is running on port 5000\n> +       if running on virtual machine use:\n> +       http://<MACHINE IP>:5000/send_message?recipient=<RECIPIENT ADDRESS>&message=<MSG>\n> +\n> +       If running locally use:\n> +       http://localhost:5000/send_message?recipient=<RECIPIENT ADDRESS>&message=<MSG>\n> +\n> +    2. Responds to incoming messages with a wikipedia page on the topic:\n> +       Send a message with a topic (e.g., 'Hawaii') to the XMPP account the server is using\n> +       It should respond with a Wikipedia page (when one exists)\n> +\n> +## Setup\n> +\n> +Follow the intstructions at the\n>\n> instructions\n> ------------------------------\n>\n> In appengine/standard/xmpp_wikibot/README.md\n> <https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#pullrequestreview-5112761>\n> :\n>\n> > +       http://<MACHINE IP>:5000/send_message?recipient=<RECIPIENT ADDRESS>&message=<MSG>\n> +\n> +       If running locally use:\n> +       http://localhost:5000/send_message?recipient=<RECIPIENT ADDRESS>&message=<MSG>\n> +\n> +    2. Responds to incoming messages with a wikipedia page on the topic:\n> +       Send a message with a topic (e.g., 'Hawaii') to the XMPP account the server is using\n> +       It should respond with a Wikipedia page (when one exists)\n> +\n> +## Setup\n> +\n> +Follow the intstructions at the\n> +[Compute Engine Quickstart Guide](https://cloud.google.com/compute/docs/quickstart-linux)\n> +on how to create a project, create a virtual machine, and connect to your\n> +instance via SSH. Once you have done this, you may jump to 'Installing files\n> +and dependencies'\n>\n> ...jump to '[Installing files and dependencies](#installing-files-and-dependencies)'\n>\n> ------------------------------\n>\n> In appengine/standard/xmpp_wikibot/README.md\n> <https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#pullrequestreview-5112761>\n> :\n>\n> > +## Setup\n> +\n> +Follow the intstructions at the\n> +[Compute Engine Quickstart Guide](https://cloud.google.com/compute/docs/quickstart-linux)\n> +on how to create a project, create a virtual machine, and connect to your\n> +instance via SSH. Once you have done this, you may jump to 'Installing files\n> +and dependencies'\n> +\n> +You should also download the [Google Cloud SDK](https://cloud.google.com/sdk/).\n> +It will allow you to access many of the features of Google Compute Engine via\n> +your local machine.\n> +\n> +\n> +### Installing files and dependencies\n> +\n> +First, install the wikibot.py and requirements.txt files onto your remote\n>\n> `wikibot.py` ... `requirements.txt`\n>\n> (ie surround with backticks, by convention)\n> ------------------------------\n>\n> In appengine/standard/xmpp_wikibot/README.md\n> <https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#pullrequestreview-5112761>\n> :\n>\n> > +[Compute Engine Quickstart Guide](https://cloud.google.com/compute/docs/quickstart-linux)\n> +on how to create a project, create a virtual machine, and connect to your\n> +instance via SSH. Once you have done this, you may jump to 'Installing files\n> +and dependencies'\n> +\n> +You should also download the [Google Cloud SDK](https://cloud.google.com/sdk/).\n> +It will allow you to access many of the features of Google Compute Engine via\n> +your local machine.\n> +\n> +\n> +### Installing files and dependencies\n> +\n> +First, install the wikibot.py and requirements.txt files onto your remote\n> +instance. See the guide on\n> +[Transferring Files](https://cloud.google.com/compute/docs/instances/transfer-files)\n> +for more information on how to do this using the Mac file browser, scp, or\n>\n> `scp`\n>\n> ------------------------------\n>\n> In appengine/standard/xmpp_wikibot/README.md\n> <https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#pullrequestreview-5112761>\n> :\n>\n> > +## Running the sample\n> +\n> +You'll need to have an XMPP account prior to actually running the sample.\n> +If you do not have one, you can easily create an account at one of the many\n> +XMPP servers such as [Jabber.at](https://jabber.at/account/register/).\n> +Once you have an account, run the following command:\n> +\n> +    python wikibot.py\n> +\n> +Then add the username (e.g., 'bob@jabber.at') and password for the account that\n> +you'd like to use for your chatbot.\n> +\n> +\n> +### Running on your local machine\n> +\n> +You may also run the sample locally by simply copying wikibot.py to a project\n>\n> `wikibot.py`\n>\n> ------------------------------\n>\n> In appengine/standard/xmpp_wikibot/wikibot.py\n> <https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#pullrequestreview-5112761>\n> :\n>\n> > +# ourselves to UTF-8.\n> +if sys.version_info < (3, 0):\n> +    from sleekxmpp.util.misc_ops import setdefaultencoding\n> +    setdefaultencoding('utf8')\n> +else:\n> +    raw_input = input\n> +\n> +app = Flask(__name__)\n> +\n> +chat_client = None #this will be initialized when the wikibot is constructed\n> +\n> +@app.route('/send_message', methods=['GET'])\n> +def send_message():\n> +    try:\n> +        recipient = request.args.get('recipient')\n> +        message = request.args.get('message')\n>\n> If you're using .get, there should never be a KeyError\n> <http://werkzeug.pocoo.org/docs/0.11/datastructures/#werkzeug.datastructures.MultiDict.get>\n> ------------------------------\n>\n> In appengine/standard/xmpp_wikibot/wikibot.py\n> <https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#pullrequestreview-5112761>\n> :\n>\n> > +chat_client = None #this will be initialized when the wikibot is constructed\n> +\n> +@app.route('/send_message', methods=['GET'])\n> +def send_message():\n> +    try:\n> +        recipient = request.args.get('recipient')\n> +        message = request.args.get('message')\n> +    except KeyError as e:\n> +        logging.info(\"key error: {0}\".format(e))\n> +\n> +    if chat_client and recipient and message:\n> +        chat_client.send_message(mto=recipient, mbody=message)\n> +        return \"message sent to:\" + recipient + \" with body:\" + message\n> +    else:\n> +        logging.info(\"chat client or recipient or message does not exist!\")\n> +    return \"message failed to send\"\n>\n> Should probably return an error code as well:\n>\n> return 'message failed to send', 500\n>\n> ------------------------------\n>\n> In appengine/standard/xmpp_wikibot/wikibot.py\n> <https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#pullrequestreview-5112761>\n> :\n>\n> > +    def message(self, msg):\n> +        \"\"\"\n> +        Process incoming message stanzas. Be aware that this also\n> +        includes MUC messages and error messages. It is usually\n> +        a good idea to check the messages's type before processing\n> +        or sending replies. If the message is the appropriate type,\n> +        then the bot checks wikipedia to see if the message string\n> +        exists as a page on the site. If so, it sends this link back\n> +        to the sender in the reply.\n> +        Arguments:\n> +            msg -- The received message stanza. See the SleekXMPP documentation\n> +                   for stanza objects and the Message stanza to see\n> +                   how it may be used.\n> +        \"\"\"\n> +        if msg['type'] in ('chat', 'normal'):\n> +            msg_body = \"%(body)s\" % msg\n>\n> Couldn't you just do msg_body = msg['body']? The string format seems\n> gratuitous...\n>\n> —\n> You are receiving this because you were mentioned.\n>\n>\n> Reply to this email directly, view it on GitHub\n> <https://github.com/GoogleCloudPlatform/python-docs-samples/pull/596#pullrequestreview-5112761>,\n> or mute the thread\n> <https://github.com/notifications/unsubscribe-auth/AUBaDtK349qsW2OuyQGYvBABm3scWo3lks5q16iXgaJpZM4KbnJO>\n> .\n>\n>\n"}}
{"actor":{"display_login":"mogar1980"}}