fixing multiple problems (#8)
diff --git a/README.md b/README.md
index 357826f..6e12ccb 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# openwhisk-slackinvite
Simple webpage for invitations for Apache OpenWhisk Slack Community
-Join our Slack https://csantanapr.github.io/openwhisk-slackinvite
+Join our Slack https://openwhisk.github.io/openwhisk-slackinvite
Backend is implemented as a serverless action with api gateway route
@@ -12,7 +12,7 @@
Create the action using `wsk` CLI and set default parameters
```
-wsk create slackinvite action.js -p org "myslackteam" -p slacktoken "xop-12345..."
+wsk action create slackinvite action.js -p org "myslackteam" -p slacktoken "xop-12345..."
```
The org is the Slack team name, usually the hostname from your .slack.com.
diff --git a/action.js b/action.js
index 2561dd3..52289cd 100644
--- a/action.js
+++ b/action.js
@@ -1,19 +1,27 @@
//jshint esversion:6
var request = require("request");
-function main({email, org, slacktoken}) {
+function main({ email, org, slacktoken }) {
return new Promise((resolve, reject) => {
request.post({
url: `https://${org}.slack.com/api/users.admin.invite`,
form: {
- email: email,
- token: slacktoken,
- set_active: true
+ email: email,
+ token: slacktoken,
+ set_active: true
+ }
+ }, (err, httpResponse, body) => {
+ if (err) {
+ reject({ message: "Error" + err });
+ } else {
+ body = JSON.parse(body);
+ if (body.ok) {
+ resolve({
+ message: `Success! Check ${email} for an invite from Slack.`
+ });
+ } else {
+ reject({ message: body.error });
}
- },(err, httpResponse, body)=>{
- if(err) reject({Error:"Error"+err});
- resolve({
- message:`Success! Check ${email} for an invite from Slack.`
- });
+ }
});
});
}
diff --git a/index.html b/index.html
index d0b7b0a..687a6e3 100644
--- a/index.html
+++ b/index.html
@@ -85,13 +85,16 @@
placeholder="jane.doe@example.com" required=""
type="email"> </div>
<button type="button" class="btn btn-primary" style="margin:
- 5px;">Send invitation</button> </form>
+ 5px;">Send invitation</button>
+ <div id="result">
+ </form>
</div>
<div class="inner">
<p>We are a friendly, respectful and inclusive community!</p>
</div>
<div class="footer"><a href="https://openwhisk-team.slack.com/"> </a>
<p><i>Code for Slack invite (this page) is on github:</i><br>
+
<i> </i><i><a
href="https://github.com/openwhisk/openwhisk-slackinvite"
target="blank">https://github.com/openwhisk/openwhisk-slackinvite</a></i></p>
@@ -104,16 +107,23 @@
var email = $('#inputEmail');
var actionUrl = "https://545303d4-dd03-4cfc-a553-4253f7929dfd-gws.api-gw.mybluemix.net/openwhisk-team/slackinvite";
function handler() {
- var email = $("input")[0].value;
- $.get(actionUrl, { email: email })
+ $.get(actionUrl, { email: email[0].value })
.done(function (data) {
+ btn.removeClass("btn-danger");
btn.addClass("btn-success");
btn.html("WOOT. CHECK YOUR EMAIL!");
res.html(data.message);
})
.fail(function (err) {
- res.html(err.statusText + ":Your invitation didn't work :-( ");
- btn.addClass("btn-error");
+ btn.addClass("btn-danger");
+ btn.html("Problem with invite");
+ if(err.responseJSON) console.log(err.responseJSON)
+ if(err.responseJSON && err.responseJSON.error && err.responseJSON.error.message){
+ res.html(err.responseJSON.error.message);
+ } else {
+ res.html(err.statusText + ":Your invitation didn't work :-( ");
+ }
+
});
}
btn.click(handler);
@@ -127,6 +137,7 @@
btn.prop("disabled", false);
}
}
+ email.change(validate);
email.keyup(validate);
})
</script>