Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

fix(messenger): use the good FB template for Image #144

Merged
merged 7 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions broid-alexa/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2352,18 +2352,14 @@ mimic-fn@^1.0.0:
dependencies:
brace-expansion "^1.0.0"

minimist@0.0.8:
minimist@0.0.8, minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

minimist@^1.1.3, minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"

"mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
Expand Down
2 changes: 1 addition & 1 deletion broid-callr/lib/core/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Parser {
return Promise.resolve(activitystreams)
.then((as2) => {
if (utils_1.isUrl(normalized.text)) {
return utils_1.fileInfo(normalized.text)
return utils_1.fileInfo(normalized.text, this.logger)
.then((infos) => {
const mediaType = infos.mimetype;
if (mediaType.startsWith('image/')) {
Expand Down
6 changes: 1 addition & 5 deletions broid-kik/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2514,18 +2514,14 @@ mime@1.3.4:
dependencies:
brace-expansion "^1.0.0"

minimist@0.0.8:
minimist@0.0.8, minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

minimist@^1.1.3, minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"

"mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
Expand Down
6 changes: 1 addition & 5 deletions broid-line/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2494,18 +2494,14 @@ mime@1.3.4:
dependencies:
brace-expansion "^1.0.0"

minimist@0.0.8:
minimist@0.0.8, minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

minimist@^1.1.3, minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"

"mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
Expand Down
7 changes: 6 additions & 1 deletion broid-messenger/lib/core/Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ class Adapter {
listen() {
return Rx_1.Observable.fromEvent(this.emitter, 'message')
.mergeMap((event) => this.parser.normalize(event))
.mergeMap((messages) => Rx_1.Observable.from(messages))
.mergeMap((messages) => {
if (!messages || R.isEmpty(messages)) {
return Rx_1.Observable.empty();
}
return Rx_1.Observable.from(messages);
})
.mergeMap((message) => this.user(message.author)
.then((author) => R.assoc('authorInformation', author, message)))
.mergeMap((normalized) => this.parser.parse(normalized))
Expand Down
2 changes: 1 addition & 1 deletion broid-messenger/lib/core/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Parser {
return Promise.resolve(a)
.then((am) => {
if (am.url) {
return utils_1.fileInfo(am.url.split('?')[0])
return utils_1.fileInfo(am.url.split('?')[0], this.logger)
.then((infos) => R.assoc('mediaType', infos.mimetype, am));
}
return null;
Expand Down
36 changes: 23 additions & 13 deletions broid-messenger/lib/core/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,28 @@ function createButtons(buttons) {
}
exports.createButtons = createButtons;
function createAttachment(name, content, buttons, imageURL) {
return {
payload: {
elements: [{
buttons: buttons && !R.isEmpty(buttons) ? buttons : null,
image_url: imageURL || '',
item_url: '',
subtitle: content !== name ? content : '',
title: name || '',
}],
template_type: 'generic',
},
type: 'template',
};
if (imageURL && (!name || R.isEmpty(name)) && (!buttons || R.isEmpty(buttons))) {
return {
payload: {
url: imageURL,
},
type: 'image',
};
}
else {
return {
payload: {
elements: [{
buttons: buttons && !R.isEmpty(buttons) ? buttons : null,
image_url: imageURL || '',
item_url: '',
subtitle: content !== name ? content : '',
title: !name || R.isEmpty(name) ? content.substring(0, 10) : name,
}],
template_type: 'generic',
},
type: 'template',
};
}
}
exports.createAttachment = createAttachment;
5 changes: 4 additions & 1 deletion broid-messenger/src/core/Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ export class Adapter {
public listen(): Observable<object> {
return Observable.fromEvent(this.emitter, 'message')
.mergeMap((event: IWebHookEvent) => this.parser.normalize(event))
.mergeMap((messages: any) => Observable.from(messages))
.mergeMap((messages: any) => {
if (!messages || R.isEmpty(messages)) { return Observable.empty(); }
return Observable.from(messages);
})
.mergeMap((message: any) => this.user(message.author)
.then((author) => R.assoc('authorInformation', author, message)))
.mergeMap((normalized) => this.parser.parse(normalized))
Expand Down
35 changes: 22 additions & 13 deletions broid-messenger/src/core/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,26 @@ export function createAttachment(name: string,
content: string,
buttons?: any[],
imageURL?: any): object {
return {
payload: {
elements: [{
buttons: buttons && !R.isEmpty(buttons) ? buttons : null,
image_url: imageURL || '',
item_url: '',
subtitle: content !== name ? content : '',
title: name || '',
}],
template_type: 'generic',
},
type: 'template',
};
if (imageURL && (!name || R.isEmpty(name)) && (!buttons || R.isEmpty(buttons))) { // image
return {
payload: {
url: imageURL,
},
type: 'image',
};
} else { // card
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need the else.

return {
payload: {
elements: [{
buttons: buttons && !R.isEmpty(buttons) ? buttons : null,
image_url: imageURL || '',
item_url: '',
subtitle: content !== name ? content : '',
title: !name || R.isEmpty(name) ? content.substring(0, 10) : name,
}],
template_type: 'generic',
},
type: 'template',
};
}
}
2 changes: 1 addition & 1 deletion broid-ms-teams/lib/core/Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class Adapter {
return messageBuilder;
}
else {
return utils_1.fileInfo(url)
return utils_1.fileInfo(url, this.logger)
.then((infos) => {
messageAttachments = [{ contentType: infos.mimetype, contentUrl: url }, hero];
messageBuilder.attachments(messageAttachments);
Expand Down
4 changes: 2 additions & 2 deletions broid-ms-teams/lib/core/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class Parser {
const attachmentVideos = R.filter((attachment) => attachment.contentType.startsWith('video')
|| attachment.contentType === 'application/octet-stream', normalized.attachments);
const assoc = (attachment, infos, fileType) => R.assoc('name', attachment.name, R.assoc('contentUrl', attachment.contentUrl, R.assoc('fileType', fileType, infos)));
return Promise.map(attachmentImages, (attachment) => utils_1.fileInfo(attachment.name).then((infos) => assoc(attachment, infos, 'Image')))
.then((dataImages) => Promise.map(attachmentVideos, (attachment) => utils_1.fileInfo(attachment.name).then((infos) => assoc(attachment, infos, 'Video')))
return Promise.map(attachmentImages, (attachment) => utils_1.fileInfo(attachment.name, this.logger).then((infos) => assoc(attachment, infos, 'Image')))
.then((dataImages) => Promise.map(attachmentVideos, (attachment) => utils_1.fileInfo(attachment.name, this.logger).then((infos) => assoc(attachment, infos, 'Video')))
.then((dataVideos) => R.concat(dataImages, dataVideos)))
.then((fileInfos) => {
const count = R.length(fileInfos);
Expand Down
2 changes: 1 addition & 1 deletion broid-skype/lib/core/Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Adapter {
return messageBuilder;
}
else {
return utils_1.fileInfo(url)
return utils_1.fileInfo(url, this.logger)
.then((infos) => {
messageAttachments = [{ contentType: infos.mimetype, contentUrl: url }, hero];
messageBuilder.attachments(messageAttachments);
Expand Down
4 changes: 2 additions & 2 deletions broid-skype/lib/core/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class Parser {
const attachmentVideos = R.filter((attachment) => attachment.contentType.startsWith('video')
|| attachment.contentType === 'application/octet-stream', normalized.attachments);
const assoc = (attachment, infos, fileType) => R.assoc('name', attachment.name, R.assoc('contentUrl', attachment.contentUrl, R.assoc('fileType', fileType, infos)));
return Promise.map(attachmentImages, (attachment) => utils_1.fileInfo(attachment.name).then((infos) => assoc(attachment, infos, 'Image')))
.then((dataImages) => Promise.map(attachmentVideos, (attachment) => utils_1.fileInfo(attachment.name).then((infos) => assoc(attachment, infos, 'Video')))
return Promise.map(attachmentImages, (attachment) => utils_1.fileInfo(attachment.name, this.logger).then((infos) => assoc(attachment, infos, 'Image')))
.then((dataImages) => Promise.map(attachmentVideos, (attachment) => utils_1.fileInfo(attachment.name, this.logger).then((infos) => assoc(attachment, infos, 'Video')))
.then((dataVideos) => R.concat(dataImages, dataVideos)))
.then((fileInfos) => {
const count = R.length(fileInfos);
Expand Down
2 changes: 1 addition & 1 deletion broid-slack/lib/core/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Parser {
let url = normalized.text.substr(1);
url = url.substring(0, url.length - 1);
if (utils_1.isUrl(url)) {
return utils_1.fileInfo(url)
return utils_1.fileInfo(url, this.logger)
.then((infos) => {
const mediaType = infos.mimetype;
let fileType = null;
Expand Down
6 changes: 3 additions & 3 deletions broid-telegram/lib/core/Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Adapter {
this.webhookServer.listen();
}
this.session = new TelegramBot(this.token);
this.session.setWebHook(`${this.webhookURL}${this.token}`);
this.session.setWebHook(`${this.webhookURL}${this.serviceId()}`);
this.connected = true;
return Rx_1.Observable.of({ type: 'connected', serviceID: this.serviceId() });
}
Expand Down Expand Up @@ -170,8 +170,8 @@ class Adapter {
this.session.processUpdate(req.body);
res.sendStatus(200);
};
router.post(`/${this.token}`, handle);
router.get(`/${this.token}`, handle);
router.post(`/${this.serviceId()}`, handle);
router.get(`/${this.serviceId()}`, handle);
return router;
}
}
Expand Down
2 changes: 1 addition & 1 deletion broid-telegram/lib/core/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Parser {
type: R.toLower(chatType) === 'private'
? 'Person' : 'Group',
};
return utils_1.fileInfo(normalized.text)
return utils_1.fileInfo(normalized.text, this.logger)
.then((infos) => {
const mimetype = infos.mimetype;
if (mimetype.startsWith('image/') || mimetype.startsWith('video/')) {
Expand Down
2 changes: 1 addition & 1 deletion broid-twitter/lib/core/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Parser {
return Promise.map(normalized.attachments, (attachment) => {
const url = R.prop('url', attachment);
if (url) {
return utils_1.fileInfo(url).then((infos) => R.assoc('mimetype', infos.mimetype, attachment));
return utils_1.fileInfo(url, this.logger).then((infos) => R.assoc('mimetype', infos.mimetype, attachment));
}
return null;
})
Expand Down
2 changes: 1 addition & 1 deletion broid-twitter/lib/test/fixtures/broid/message.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"hello world","id":"823034222432686081","type":"Note"},"published":1485061624,"target":{"id":"258891753","name":"Issam Hakimi","type":"Group"},"type":"Create"}
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"hello world","id":"823034222432686081","type":"Note"},"published":1485061624,"target":{"id":"2932680926","name":"broid","type":"Group"},"type":"Create"}
2 changes: 1 addition & 1 deletion broid-twitter/lib/test/fixtures/broid/messagePrivate.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"hello on private message","id":"823033244023193604","type":"Note"},"published":1485061391,"target":{"id":"258891753","name":"Issam Hakimi","type":"Person"},"type":"Create"}
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"hello on private message","id":"823033244023193604","type":"Note"},"published":1485061391,"target":{"id":"2932680926","name":"broid","type":"Person"},"type":"Create"}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"private gif https://t.co/HIq5M3zMAD","id":"823033704817786883","mediaType":"video/mp4","type":"Video","url":"https://video.twimg.com/dm_gif/823033665722535936/SH97vg8M-ASzeyqynK6ycsLboQ5o2HvkX0W0zAwlgSi6o9DS0B.mp4"},"published":1485061501,"target":{"id":"258891753","name":"Issam Hakimi","type":"Person"},"type":"Create"}
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"private gif https://t.co/HIq5M3zMAD","id":"823033704817786883","mediaType":"video/mp4","type":"Video","url":"https://video.twimg.com/dm_gif/823033665722535936/SH97vg8M-ASzeyqynK6ycsLboQ5o2HvkX0W0zAwlgSi6o9DS0B.mp4"},"published":1485061501,"target":{"id":"2932680926","name":"broid","type":"Person"},"type":"Create"}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"ielo app","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"published":1485064400,"target":{"id":"248881752","name":"Issam Hakimi","type":"Person"},"type":"Create","object":{"content":"hello world on private #tags","id":"823045866957271043","type":"Note","tag":[{"id":"tags","name":"tags","type":"Object"}]}}
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"ielo app","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"published":1485064400,"target":{"id":"2932680926","name":"ielo app","type":"Person"},"type":"Create","object":{"content":"hello world on private #tags","id":"823045866957271043","type":"Note","tag":[{"id":"tags","name":"tags","type":"Object"}]}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"hello world with gif https://t.co/DrkMc7hUfY","id":"823034568898998272","mediaType":"image/jpeg","type":"Image","url":"https://pbs.twimg.com/tweet_video_thumb/C2wBjBQUoAABGpv.jpg"},"published":1485061707,"target":{"id":"258891753","name":"Issam Hakimi","type":"Group"},"type":"Create"}
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"hello world with gif https://t.co/DrkMc7hUfY","id":"823034568898998272","mediaType":"image/jpeg","type":"Image","url":"https://pbs.twimg.com/tweet_video_thumb/C2wBjBQUoAABGpv.jpg"},"published":1485061707,"target":{"id":"2932680926","name":"broid","type":"Group"},"type":"Create"}
2 changes: 1 addition & 1 deletion broid-twitter/lib/test/fixtures/broid/messageWithTag.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"ielo app","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"published":1485064277,"target":{"id":"248881752","name":"Issam Hakimi","type":"Group"},"type":"Create","object":{"content":"hello world #tags","id":"823045350755827712","type":"Note","tag":[{"id":"tags","name":"tags","type":"Object"}]}}
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"ielo app","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"published":1485064277,"target":{"id":"2932680926","name":"ielo app","type":"Group"},"type":"Create","object":{"content":"hello world #tags","id":"823045350755827712","type":"Note","tag":[{"id":"tags","name":"tags","type":"Object"}]}}
2 changes: 1 addition & 1 deletion broid-twitter/src/test/fixtures/broid/message.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"hello world","id":"823034222432686081","type":"Note"},"published":1485061624,"target":{"id":"258891753","name":"Issam Hakimi","type":"Group"},"type":"Create"}
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"hello world","id":"823034222432686081","type":"Note"},"published":1485061624,"target":{"id":"2932680926","name":"broid","type":"Group"},"type":"Create"}
2 changes: 1 addition & 1 deletion broid-twitter/src/test/fixtures/broid/messagePrivate.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"hello on private message","id":"823033244023193604","type":"Note"},"published":1485061391,"target":{"id":"258891753","name":"Issam Hakimi","type":"Person"},"type":"Create"}
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"hello on private message","id":"823033244023193604","type":"Note"},"published":1485061391,"target":{"id":"2932680926","name":"broid","type":"Person"},"type":"Create"}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"private gif https://t.co/HIq5M3zMAD","id":"823033704817786883","mediaType":"video/mp4","type":"Video","url":"https://video.twimg.com/dm_gif/823033665722535936/SH97vg8M-ASzeyqynK6ycsLboQ5o2HvkX0W0zAwlgSi6o9DS0B.mp4"},"published":1485061501,"target":{"id":"258891753","name":"Issam Hakimi","type":"Person"},"type":"Create"}
{"@context":"https://www.w3.org/ns/activitystreams","actor":{"id":"2932680926","name":"broid","type":"Person"},"generator":{"id":"test_service","name":"twitter","type":"Service"},"object":{"content":"private gif https://t.co/HIq5M3zMAD","id":"823033704817786883","mediaType":"video/mp4","type":"Video","url":"https://video.twimg.com/dm_gif/823033665722535936/SH97vg8M-ASzeyqynK6ycsLboQ5o2HvkX0W0zAwlgSi6o9DS0B.mp4"},"published":1485061501,"target":{"id":"2932680926","name":"broid","type":"Person"},"type":"Create"}
Loading