-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
85 changed files
with
4,367 additions
and
907 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
{ | ||
"name": "appmixer.freshdesk", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"changelog": { | ||
"1.0.1": [ | ||
"Initial version" | ||
], | ||
"1.0.2": [ | ||
"Fixed incorrect icons for `ListAgents` and `ListContacts`." | ||
], | ||
"1.0.3": [ | ||
"Fixed an issue with the `ListContacts` component when using 'Created At' and 'Updated At' filters." | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 10 additions & 19 deletions
29
src/appmixer/google/gmail/AddLabelsToEmail/AddLabelsToEmail.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
'use strict'; | ||
const GoogleApi = require('googleapis'); | ||
const commons = require('../../google-commons'); | ||
const { promisify } = require('util'); | ||
|
||
// GoogleApi initialization & promisify of some api function for convenience | ||
const gmail = GoogleApi.gmail('v1'); | ||
|
||
const commons = require('../gmail-commons'); | ||
module.exports = { | ||
|
||
async receive(context) { | ||
|
||
const { | ||
emailId, | ||
labels: { AND: labels } | ||
} = context.messages.in.content; | ||
const modifyLabel = promisify(gmail.users.messages.modify.bind(gmail.users.messages.modify)); | ||
const email = await modifyLabel({ | ||
auth: commons.getOauth2Client(context.auth), | ||
userId: 'me', | ||
quotaUser: context.auth.userId, | ||
resource: { | ||
const endpoint = `/users/me/messages/${emailId}/modify`; | ||
const options = { | ||
method: 'POST', | ||
data: { | ||
addLabelIds: labels.map(label => label.name) | ||
}, | ||
id: emailId | ||
}); | ||
return context.sendJson(email, 'out'); | ||
} | ||
}; | ||
|
||
const email = await commons.callEndpoint(context, endpoint, options); | ||
return context.sendJson(email.data, 'out'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,45 @@ | ||
{ | ||
"name": "appmixer.google.gmail.AddLabelsToEmail", | ||
"author": "Harsha Surisetty <[email protected]>", | ||
"author": "Appmixer <[email protected]>", | ||
"description": "Adds a label(s) to emails.", | ||
"private": false, | ||
"version": "1.0.0", | ||
"auth": { | ||
"service": "appmixer:google", | ||
"service": "appmixer:google:gmail", | ||
"scope": ["https://www.googleapis.com/auth/gmail.modify"] | ||
}, | ||
"quota": { | ||
"manager": "appmixer:google:gmail", | ||
"maxWait": 5000, | ||
"resources": "messages.polling", | ||
"resources": "messages.modify", | ||
"scope": { | ||
"userId": "{{userId}}" | ||
} | ||
}, | ||
"inPorts": [ | ||
{ | ||
"name": "in", | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"emailId": { | ||
"type": "string" | ||
}, | ||
"labels": { | ||
"type": "object" | ||
} | ||
}, | ||
"required": ["emailId"] | ||
}, | ||
"inspector": { | ||
"inputs": { | ||
"emailId": { | ||
"type": "text", | ||
"index": 1, | ||
"label": "Email ID", | ||
"tooltip": "Email ID of the message that you want to retrieve." | ||
"index": 1, | ||
"tooltip": "Select an Email from the list or insert Email ID to add labels", | ||
"source": { | ||
"url": "/component/appmixer/google/gmail/ListEmails?outPort=out", | ||
"data": { | ||
"messages": { | ||
"in/limit": "20", | ||
"in/outputType": "emails" | ||
}, | ||
"properties": { | ||
"sendWholeArray": true, | ||
"variableFetch": true | ||
}, | ||
"transform": "./ListEmails#emailsToSelectArray" | ||
} | ||
} | ||
}, | ||
"labels": { | ||
"type": "expression", | ||
|
@@ -52,21 +54,40 @@ | |
"type": "select", | ||
"label": "Name", | ||
"index": 1, | ||
"tooltip": "Select a name of the existing label.", | ||
"tooltip": "Select a label to add to the email", | ||
"source": { | ||
"url": "/component/appmixer/google/gmail/ListLabels?outPort=out", | ||
"data": { | ||
"properties": { "sendWholeArray": true }, | ||
"transform": "./ListLabels#labelsToSelectArray" | ||
"transform": "./ListLabels#labelsToSelectArrayFiltered" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"emailId": { | ||
"type": "string" | ||
}, | ||
"labels": { | ||
"type": "object" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"outPorts": ["out"], | ||
"outPorts": [ | ||
{ | ||
"name": "out", | ||
"options": [ | ||
{ "label": "Email ID", "value": "id" }, | ||
{ "label": "Thread ID", "value": "threadId" } | ||
] | ||
} | ||
], | ||
"icon": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij4KICA8ZyBpZD0iR3JvdXBfNTQ1IiBkYXRhLW5hbWU9Ikdyb3VwIDU0NSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTM3NiAtNjQpIj4KICAgIDxyZWN0IGlkPSJSZWN0YW5nbGVfMzMyNyIgZGF0YS1uYW1lPSJSZWN0YW5nbGUgMzMyNyIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgzNzYgNjQpIiBmaWxsPSJub25lIi8+CiAgICA8ZyBpZD0iR3JvdXBf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8+CiAgICAgIDxwYXRoIGlkPSJQYXRoXzE3NiIgZGF0YS1uYW1lPSJQYXRoIDE3NiIgZD0iTTUyLDQ0LjAzM3YxLjgxOGw0LjU0NSwzLjQwOVY0My4zNTFMNTUuMjczLDQyLjRBMi4wNDUsMi4wNDUsMCwwLDAsNTIsNDQuMDMzWiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTQwNzIgLTcxOTcpIiBmaWxsPSIjYzUyMjFmIi8+CiAgICA8L2c+CiAgPC9nPgo8L3N2Zz4K" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,55 @@ | ||
'use strict'; | ||
const GoogleApi = require('googleapis'); | ||
const commons = require('../../google-commons'); | ||
const Promise = require('bluebird'); | ||
const mailcomposer = require('mailcomposer'); | ||
|
||
// GoogleApi initialization & promisify of some api function for convenience | ||
const gmail = GoogleApi.gmail('v1'); | ||
const createDraft = Promise.promisify(gmail.users.drafts.create, { context: gmail.users.drafts }); | ||
const emailCommons = require('../gmail-commons'); | ||
|
||
module.exports = { | ||
async receive(context) { | ||
const { | ||
from = context.profileInfo.email, | ||
sender, | ||
to, | ||
cc, | ||
bcc, | ||
subject, | ||
text, | ||
html, | ||
signature, | ||
labels, | ||
attachments = {} | ||
} = context.messages.in.content; | ||
|
||
receive(context) { | ||
const mail = { | ||
from: sender ? `${sender} <${from}>` : from, | ||
to, | ||
cc, | ||
bcc, | ||
subject, | ||
text, | ||
html, | ||
attachments: await emailCommons.addAttachments(context, attachments) | ||
}; | ||
|
||
/** | ||
* @type MailComposer | ||
*/ | ||
let mail = context.messages.in.content; | ||
if (mail.from && mail.sender) { | ||
mail.from = `${mail.sender} <${mail.from}>`; | ||
} else if (mail.sender) { | ||
mail.from = `${mail.sender} <${context.profileInfo.email}>`; | ||
} | ||
emailCommons.addSignature(mail, signature); | ||
|
||
const emailContent = await emailCommons.buildEmail(mail); | ||
|
||
return new Promise((resolve, reject) => { | ||
mailcomposer(mail).build((err, email) => { | ||
if (err) { | ||
return reject(err); | ||
const result = await emailCommons.callEndpoint(context, '/users/me/drafts', { | ||
method: 'POST', | ||
data: { | ||
message: { | ||
raw: emailContent.toString('base64').replace(/\+/gi, '-').replace(/\//gi, '_').replace(/=+$/, '') | ||
} | ||
resolve(email); | ||
}); | ||
}).then(email => { | ||
return createDraft({ | ||
auth: commons.getOauth2Client(context.auth), | ||
userId: 'me', | ||
quotaUser: context.auth.userId, | ||
resource: { | ||
message: { | ||
// URI-safe base64 | ||
raw: email.toString('base64').replace(/\+/gi, '-').replace(/\//gi, '_') | ||
} | ||
} | ||
}); | ||
|
||
if (labels && labels.AND && labels.AND.some(label => label.name)) { | ||
await emailCommons.callEndpoint(context, `/users/me/messages/${result.data.message.id}/modify`, { | ||
method: 'POST', | ||
data: { | ||
addLabelIds: labels.AND.filter(label => label.name).map(label => label.name) | ||
} | ||
}).then(result => { | ||
return context.sendJson(result, 'draft'); | ||
}); | ||
}); | ||
} | ||
|
||
return context.sendJson(result.data, 'draft'); | ||
} | ||
}; |
Oops, something went wrong.