Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change „avatarUrl“ to „avatar_url“ #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Invite the webhook bridge to your room (`@_webhook:t2bot.io`) and send the messa
"text": "Hello world!",
"format": "plain",
"displayName": "My Cool Webhook",
"avatarUrl": "http://i.imgur.com/IDOBtEJ.png"
"avatar_url": "http://i.imgur.com/IDOBtEJ.png"
}
```

Expand Down
2 changes: 1 addition & 1 deletion config/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ webhookBot:
# Appearance options for the Matrix bot
appearance:
displayName: "Webhook Bridge"
avatarUrl: "http://i.imgur.com/IDOBtEJ.png" # webhook icon
avatar_url: "http://i.imgur.com/IDOBtEJ.png" # webhook icon

# Provisioning API options
provisioning:
Expand Down
2 changes: 1 addition & 1 deletion config/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ properties:
properties:
displayName:
type: "string"
avatarUrl:
avatar_url:
type: "string"
logging:
type: "object"
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const cli = new Cli({
localpart: "_webhook",
appearance: {
displayName: "Webhook Bridge",
avatarUrl: "http://i.imgur.com/IDOBtEJ.png" // webhook bridge icon
avatar_url: "http://i.imgur.com/IDOBtEJ.png" // webhook bridge icon
}
},
web: {
Expand Down
14 changes: 7 additions & 7 deletions src/WebhookBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,18 @@ class WebhookBridge {
LogService.info("WebhookBridge", "Updating appearance of bridge bot");

const desiredDisplayName = this._config.webhookBot.appearance.displayName || "Webhook Bridge";
const desiredAvatarUrl = this._config.webhookBot.appearance.avatarUrl || "http://i.imgur.com/IDOBtEJ.png"; // webhook icon
const desiredAvatarUrl = this._config.webhookBot.appearance.avatar_url || "http://i.imgur.com/IDOBtEJ.png"; // webhook icon

const botIntent = this.getBotIntent();

WebhookStore.getAccountData('bridge').then(botProfile => {
let avatarUrl = botProfile.avatarUrl;
if (!avatarUrl || avatarUrl !== desiredAvatarUrl) {
let avatar_url = botProfile.avatar_url;
if (!avatar_url || avatar_url !== desiredAvatarUrl) {
util.uploadContentFromUrl(this._bridge, desiredAvatarUrl, botIntent).then(mxcUrl => {
LogService.verbose("WebhookBridge", "Avatar MXC URL = " + mxcUrl);
LogService.info("WebhookBridge", "Updating avatar for bridge bot");
botIntent.setAvatarUrl(mxcUrl);
botProfile.avatarUrl = desiredAvatarUrl;
botProfile.avatar_url = desiredAvatarUrl;
WebhookStore.setAccountData('bridge', botProfile);
});
}
Expand All @@ -162,8 +162,8 @@ class WebhookBridge {
return WebhookStore.getAccountData(intent.getClient().credentials.userId).then(botProfile => {
const promises = [];

let avatarUrl = botProfile.avatarUrl;
if ((!avatarUrl || avatarUrl !== desiredAvatarUrl) && desiredAvatarUrl) {
let avatar_url = botProfile.avatar_url;
if ((!avatar_url || avatar_url !== desiredAvatarUrl) && desiredAvatarUrl) {
let uploadPromise = Promise.resolve(desiredAvatarUrl);
if (!desiredAvatarUrl.startsWith("mxc://"))
uploadPromise = util.uploadContentFromUrl(this._bridge, desiredAvatarUrl, this.getBotIntent());
Expand All @@ -172,7 +172,7 @@ class WebhookBridge {
LogService.verbose("WebhookBridge", "Avatar MXC URL = " + mxcUrl);
LogService.info("WebhookBridge", "Updating avatar for " + intent.getClient().credentials.userId);
return intent.setAvatarUrl(mxcUrl).then(() => {
botProfile.avatarUrl = desiredAvatarUrl;
botProfile.avatar_url = desiredAvatarUrl;
WebhookStore.setAccountData(intent.getClient().credentials.userId, botProfile);
});
}));
Expand Down
4 changes: 2 additions & 2 deletions src/processing/WebhookReceiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class WebhookReceiver {
},
sender: {
displayName: null,
avatarUrl: null,
avatar_url: null,
}
};

Expand All @@ -74,7 +74,7 @@ class WebhookReceiver {

// Update profile, try join, fall back to invite, and try to send message
const postFn = () => intent.sendMessage(webhookEvent.hook.roomId, matrixPayload.event);
this._bridge.updateHookProfile(intent, matrixPayload.sender.displayName, matrixPayload.sender.avatarUrl)
this._bridge.updateHookProfile(intent, matrixPayload.sender.displayName, matrixPayload.sender.avatar_url)
.then(() => {
return intent.join(webhookEvent.hook.roomId).then(postFn, err => {
LogService.error("WebhookReceiver", err);
Expand Down
6 changes: 3 additions & 3 deletions src/processing/layers/avatar/default.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = (webhook, matrix) => {
// Note: this technically doesn't do anything and solely exists to make the structure sane
if (!matrix.sender.avatarUrl)
matrix.sender.avatarUrl = null;
};
if (!matrix.sender.avatar_url)
matrix.sender.avatar_url = null;
};
6 changes: 3 additions & 3 deletions src/processing/layers/avatar/from_webhook.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = (webhook, matrix) => {
if (!matrix.sender.avatarUrl && webhook.avatarUrl)
matrix.sender.avatarUrl = webhook.avatarUrl;
};
if (!matrix.sender.avatar_url && webhook.avatar_url)
matrix.sender.avatar_url = webhook.avatar_url;
};
6 changes: 3 additions & 3 deletions src/processing/layers/avatar/slack_icon_emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const cheerio = require("cheerio");
emojione.emojiSize = '128';

module.exports = (webhook, matrix) => {
if (!matrix.sender.avatarUrl && webhook.icon_emoji) {
if (!matrix.sender.avatar_url && webhook.icon_emoji) {
// HACK: We really shouldn't have to do this element -> url conversion

const imgElement = emojione.shortnameToImage(webhook.icon_emoji);
if (imgElement == webhook.icon_emoji) return;

const srcUrl = cheerio(imgElement).attr('src');
matrix.sender.avatarUrl = srcUrl;
matrix.sender.avatar_url = srcUrl;
}
};
};
6 changes: 3 additions & 3 deletions src/processing/layers/avatar/slack_icon_url.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = (webhook, matrix) => {
if (!matrix.sender.avatarUrl && webhook.icon_url)
matrix.sender.avatarUrl = webhook.icon_url;
};
if (!matrix.sender.avatar_url && webhook.icon_url)
matrix.sender.avatar_url = webhook.icon_url;
};
2 changes: 1 addition & 1 deletion src/provisioning/InteractiveProvisioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InteractiveProvisioner {
" \"text\": \"Hello world!\",\n" +
" \"format\": \"plain\",\n" +
" \"displayName\": \"My Cool Webhook\",\n" +
" \"avatarUrl\": \"http://i.imgur.com/IDOBtEJ.png\"\n" +
" \"avatar_url\": \"http://i.imgur.com/IDOBtEJ.png\"\n" +
"}" +
"</code></pre>" +
"If you run into any issues, visit <a href=\"https://matrix.to/#/#webhooks:t2bot.io\">#webhooks:t2bot.io</a>";
Expand Down