Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Post iTunes Connect Status to Slack with Gmail using Google Apps Script
var mailAddress = "YOUR_EMAIL_ADDRSS";
var slackToken = "SLACK_TOKEN";
var searchMailQuery = 'SEARCH_QUERY'; // example: '[from:no_reply@email.apple.com YOUR_APP_NAME]';
var slackChannelId = "SLACK_CHANNEL_ID";
function getAttachment(message) {
var subject = message.getSubject();
var body = message.getPlainBody();
var result = body.match("([0-9]\.[0-9])+(\.[0-9])?");
if (!result) {
return null
}
var version = result[0];
var statuses = [
{
"subject": subject,
"version": version,
"token": "Waiting For Review",
"text": "Waiting For Review"
},
{
"subject": subject,
"version": version,
"token": "Developer Rejected",
"text": "Developer Rejected"
},
{
"subject": subject,
"version": version,
"token": "In Review",
"text": "In Review"
},
{
"subject": subject,
"version": version,
"token": "New message from App Review",
"text": "New message from App Review"
},
{
"subject": subject,
"version": version,
"token": "Pending Developer Release",
"text": "Pending Developer Release"
},
{
"subject": subject,
"version": version,
"token": "Ready for Sale",
"text": "Ready for Sale"
},
{
"subject": subject,
"version": version,
"token": "now available to test",
"text": "now available to test"
},
];
for (var status in statuses) {
if (~subject.indexOf(statuses[status].token)) {
return statuses[status];
}
}
return null;
}
function getFields(message) {
var attachment = getAttachment(message);
if (!attachment) {
return null
}
return attachment;
}
function postSlack(fields) {
var prop = PropertiesService.getScriptProperties().getProperties();
var slackApp = SlackApp.create(prop.token);
var message = fields.text + "\n"
slackApp.postMessage(slackChannelId, message, {
username : "iOS v" + fields.version + " is " + fields.token,
icon_emoji : ":rocket:",
});
}
function main() {
PropertiesService.getScriptProperties().setProperty("token", slackToken);
var threads = GmailApp.search(searchMailQuery);
for (var i = 0; i < threads.length; i++) {
var thread = threads[i];
if (!thread.isUnread()) {
continue;
}
var messages = thread.getMessages();
for (var j = 0; j < messages.length; j++) {
var message = messages[j];
if (!message || !message.isUnread()) {
continue;
}
var fields = getFields(message);
if (!fields) {
continue;
}
postSlack(fields);
message.markRead();
}
thread.markRead();
}
}
@motokiee

This comment has been minimized.

Copy link
Owner Author

commented May 1, 2018

Usage

1. Add SlackApp

  1. Open Resource > Library
  2. Add library Key: M3W5Ut3Q39AaIwLquryEPMwV62A3znfOO
  3. Set library version to 22

This script support version 22. Other versions are not supported.

2. Resolve configs

  1. Set your email address
  2. Set your slack token
  3. Set query to check your app status
  4. Set slack channel id you need to post

3. Set up trigger

  1. Open Edit > Trigger of the current project
  2. Add new trigger
  3. Set Execution to main
  4. Set Event to Time driven, Minute timer and Every 10 minutes
  5. Save

See below example.
image

Debug

This script checks your unread iTunes Connect Status email. If you would like to debug this script, you need to set email you want to debug to unread.

IMPORTANT

To receive iTunes Connect Status email, you need to set your teritory on iTunes Connect Use > Notifications > App Status Report on iTunes Connect.

Reference(Japanese)

http://tech.mercari.com/entry/2017/12/21/143000
https://speakerdeck.com/motokiee/iosfalsezi-dong-hua-toshi-zu-mihua-kodotoshe-ji-niji-zhong-suru

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.