Read the statement by Michael Teeuw here.
MMM-Slack stop randomise messages
-
Hi @saibam,
Just change:
var randomMessageId = Math.floor(Math.random() * this.slackMessages.length);to the following:
var randomMessageId = 0;It should work (unrandomizing the order), so long as the
slackMessagesarray is in ascending order. If not, and it’s in descending order, set tothis.slackMessages.length - 1instead of0. -
@ninjabreadman thanks for the answer but this will only show the latest message. I solved it in a rather long but still nice way. The idea is to show the latest 10 messages and when a new message is sent it will show it instantly.
currentMessageCount and currentMessgeId are global variables instantiated to 0. emoji_replace is my own function to include emojis in the message.if (currentMessageCount < this.slackMessages.length || currentMessageCount == 0){ currentMessageId = 0; currentMessageCount = this.slackMessages.length; } var maxAllowed = 10; var topMessages = this.slackMessages.slice(0, (maxAllowed - 1)); var maxCount = Math.min(maxAllowed, topMessages.length); if (currentMessageId == maxCount - 1) { currentMessageId = 0; } var currentMessage = topMessages[currentMessageId].message; currentMessage = emoji_replace(currentMessage); messageElement.innerHTML = currentMessage; currentMessageId ++; -
@saibam That sounds pretty good. I wanted to achive the same for the last 5 messages. So i would simpley exchange the 10 for a 5. But where do I have to put the code into ? In the mmm-slack.js ?
I would relay appreciate any help. -
@gekberlin Yes. Change maxAllowed to 5. Put it in MMM-Slack.js under the getDom: function() where it creates the html elements. I also noticed that it didnt work as expected where I had (maxCount -1) and (maxAllowed - 1). I removed the -1 and it worked like a charm.
-
@saibam Thanks for your fast reply!
I’ve put in the code but then I didn’t get any message displayed anymore.
Did I have done something wrong ?getDom: function() { var messageElement = document.createElement('div'); if (currentMessageCount < this.slackMessages.length || currentMessageCount == 0){ currentMessageId = 0; currentMessageCount = this.slackMessages.length; } var maxAllowed = 5; var topMessages = this.slackMessages.slice(0, (maxAllowed 0)); var maxCount = Math.min(maxAllowed, topMessages.length); if (currentMessageId == maxCount 0) { currentMessageId = 0; } var currentMessage = topMessages[currentMessageId].message; currentMessage = emoji_replace(currentMessage); messageElement.innerHTML = currentMessage; currentMessageId ++; } return messageElement; } }); -
@gekberlin Yes.
currentMessage = emoji_replace(currentMessage);will not work as emoji_replace is my own function for replacing :smiley: with an emoji.
so just get rid of that line and it will work.And you will also have to instantiate currentMessageId and currentMessageCount globally. I.e.
var currentMessageId = 0 var currentMessageCount = 0at the top of the js file.
-
@saibam Which Slack token do you use to connect to slack and do you have to put the leading # hash sign in the config file for the channel where it listens?
-
@mediathreat we followed the link in the readme https://api.slack.com/tokens and from there we created our own app. I’m sorry I can’t find where I found the token in there, you will have to try and error your way :) I will keep looking some but can’t guarantee I find anything. Slack API pages are a mess imo. And no you don’t need the leading # in the config file.
-
@mediathreat here is the correct link to create your token: https://api.slack.com/custom-integrations/legacy-tokens
-
Thanks! This nailed it perfectly! Hopefully the MMM-SLACK package maintainer might add this info to be clearer. Now that I have it working, I wonder if I can go in and see if I can add showing photos from a slack channel to the code base
-
@saibam do you think its possible to modify the code to get images or links that are posted into the slack channel and display them on the magic mirror?
-
@mediathreat I think it is possible, as long as the images have some kind of html address or similar, but I have no idea how to do it. I’ve moved on to other projects now :) almost finished an arcade cabinet :D
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login