8. 8
text
actionの登録 1. https://api.slack.com/docs/oauth-test-tokens からアクセストー
クン入手。
2. action を登録。Slack チーム名(org) / slacktoken はデフォル
トパラメータとしてセットする。
$ wsk action create slackinvite action.js -p org
"opencrane" -p slacktoken "xoxp-…”
ok: created action slackinvite
3. action の試験。
$ wsk action invoke -b -r slackinvite -p email amnt@jp.ibm.com
{
"message": "Success! Check amnt@jp.ibm.com for an invite
from Slack.”
}
$ cat action.js
//jshint esversion:6
var request = require("request");
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
}
},(err, httpResponse, body)=>{
if(err) reject({Error:"Error"+err});
resolve({
message:`Success! Check ${email}
for an invite from Slack.`
});
});
});
}
exports.main = main;
9. 9
text
API Gateway の作成
# API Gatewayの作成
$ wsk api-experimental create /opencrane /slackinvite GET slackinvite
ok: created API /opencrane/slackinvite GET for action /_/slackinvite
https://44081aec-c239-490d-a990-f0c37efa4746-gws.api-
gw.mybluemix.net/opencrane/slackinvite
# API Gateway 試験
$ curl -X GET https://44081aec-c239-490d-a990-f0c37efa4746-gws.api-
gw.mybluemix.net/opencrane/slackinvite?email=temp.amano@outlook.com {
"message": "Success! Check temp.amano@outlook.com for an invite from Slack."
}