From dfefde1a05ab47320cb5464b888412d6314b3d13 Mon Sep 17 00:00:00 2001 From: spasiu Date: Mon, 28 Nov 2016 16:21:40 -0500 Subject: [PATCH 1/2] Implement settings.json, add .gitignore, fix first message bug --- .gitignore | 1 + client/main.html | 1 + client/views/widget/widget.html | 3 +++ lib/routes.js | 13 +++++++++---- settings.json.example | 5 +++++ 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 client/views/widget/widget.html create mode 100644 settings.json.example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e38da20 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +settings.json diff --git a/client/main.html b/client/main.html index ebf6ed3..acb27c6 100644 --- a/client/main.html +++ b/client/main.html @@ -1,3 +1,4 @@ + diff --git a/client/views/widget/widget.html b/client/views/widget/widget.html new file mode 100644 index 0000000..2760903 --- /dev/null +++ b/client/views/widget/widget.html @@ -0,0 +1,3 @@ + diff --git a/lib/routes.js b/lib/routes.js index a6a43b2..77ff349 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -11,6 +11,10 @@ Router.map(function (){ path: '/channel/:_id' }); + this.route('widget', { + path: '/web-messenger' + }); + this.route('hook', { path: '/hook', where: 'server', @@ -23,11 +27,12 @@ Router.map(function (){ if(this.request.body.appUser) { var appUser = this.request.body.appUser; - var channel = Channels.findOne({userId: appUser._id}); - var name = appUser.givenName + " " + appUser.surname; + var channel = Channels.findOne({userId: appUser._id}) || {}; + var name = this.request.body.messages[0].name; + - if(!channel) { - channel = Channels.insert({name: name, userId: appUser._id}); + if(!channel._id) { + channel._id = Channels.insert({name: name, userId: appUser._id}); } if(this.request.body.messages) { diff --git a/settings.json.example b/settings.json.example new file mode 100644 index 0000000..5f40a7a --- /dev/null +++ b/settings.json.example @@ -0,0 +1,5 @@ +{ + "smoochKeyId": "your_key_id", + "smoochSecret": "your_secret", + "smoochAppToken": "your_apptoken" +} From 8fccb06c7225b61ee5007ae63fcdcc0436bea03d Mon Sep 17 00:00:00 2001 From: spasiu Date: Mon, 28 Nov 2016 16:24:19 -0500 Subject: [PATCH 2/2] Use keys from settings and update readme --- README.md | 10 ++++++---- server/messages.js | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2c0cf23..fae7347 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,17 @@ A sample business system built with Meteor and the Smooch API. 3. Configure a webhook: - Configure a Smooch webhook to send appUser messages to your smoochDesk app at the "/hook" route + Configure a [Smooch webhook](https://app.smooch.io/integrations/webhook) to send "_All Triggers_" to your smoochDesk app at the "/hook" route -4. Configure your secret keys +4. Configure your secret keys and appToken - In _sever/messages.js_ add your Smooch keyId and secret + Using the _settings.json.example_ file as a guide, create a _settings.json_ file that contains your appToken, secret key, and key ID 5. Run it: - `meteor run` + `meteor --settings settings.json` + + You can visit "/web-messenger" to send test messages as an end-user ## Based on Meteor Slack diff --git a/server/messages.js b/server/messages.js index a42d86d..6bc56e9 100644 --- a/server/messages.js +++ b/server/messages.js @@ -2,9 +2,9 @@ var smooch = require('smooch-core'); //import { smooch } from 'smooch-core'; var SmoochBase = new smooch({ - keyId: 'app_582d3ffb5e1e583300447d8c', - secret: 'NGKMzMLhmsP3VxRr33mVHpMa', - scope: 'app', // app or appUser + keyId: Meteor.settings.smoochKeyId, + secret: Meteor.settings.smoochSecret, + scope: 'app', }) Meteor.methods({