So I'm making request to Slack api to get messsage history of a particular channel. Everything works fine except the messages that are returned are still in slack format. Is there any way to convert it to HTML format?
Thanks.
No. The Slack api will give you the messages in Slack markup only. If you want them in html you need to convert them yourself or find a library.
Here is how to parse the Slack markup in order to convert it into another format like HTML:
If you're retrieving messages, we've included some extra details in
the sections above to help you parse the formatting syntax. This will
let you properly format it for display on a different service, or to
help your app fully understand the intent of a message. Here are the
general steps involved for detecting advanced formatting syntax:
Detect all sub-strings matching <(.*?)>
Within those sub-strings, format content starting with #C as a channel link
Format content starting with #U or #W as a user mention
Format content starting with !subteam as a user group mention
Format content starting with ! according to the rules for special mentions
For any other content within those sub-strings, format as a URL link
Once the format has been determined, check for a pipe (|) - if present, use the text following the pipe as the label for the link or
mention.
From official Slack documentation on Formatting.
Related
I am trying to create an outlook addin, that reads the selected mail in .MSG or .EML format. I found a
Stackoverflow Question with a link to this documentation how to read a mail from Graph: https://learn.microsoft.com/en-us/graph/outlook-get-mime-message. I tried to use https://graph.microsoft.com/v1.0/me/messages/{id}/$value with the Graph tester. I entered all ids i could find in the Office.context.mailbox.item but none of them gave me a valid result. So where do I have to take the id from, the Graph Tester needs?
I found that: Office.context.mailbox.item.itemId.replace('/', '-').replace('+', '_'); gets the same id, the graph gives when asking for all messages via https://graph.microsoft.com/v1.0/me/messages. I just do not know why I have to replace chars in the id.
I am currently working on a project of finding empty classrooms in our school in real time. For that purpose, I need to extract substitution published on our school page (https://ssnovohradska.edupage.org/substitution/?), since there might be any additional changes.
But when I try to extract the html source code and parse it with bs4, it cannot find the divs(class: "section print-nobreak") that contain the substitution text. When I took a look at the page source code(Ctrl+U) I found that there is only a javascript that prints it all directly.
Is there any way to extract the html after the javascript output has been already rendered?
Thanks for help!
Parsing HTML is unfortunately necessary to solve your problem. But I will explain how to find ways to avoid that in your future projects (not based on this website).
You've correctly noticed that the text is created by JavaScript code running on the page. This could also indicate that the data is either loaded from another resource (XHR/fetch call getting a response from an API) or is stored as a JSON/JS inside of the website's code. (Or is generated from an algorithm, but this is unlikely to be the case in such websites.)
The website actually uses both methods (initial render gets data stored inside of the website's code, but when you switch dates on the calendar it makes AJAX requests). You can see this by searching for ReactDOM.render(React.createElement( in the code. They're providing a HTML string to the createElement call, so I would suggest looking into the AJAX way of doing things.
Now, to check where the resource is located, all you need to do is opening Developer Tools in your favorite browser (usually Control+Shift+I) and navigating to the Network tab. Now that your network tab is open, you need to cause the website to load external data, for example, by pressing a date on the "calendar bar".
Here you will notice many external requests, but we're actually looking only for XHR calls. Click on the XHR button next to the "Filter" text field. That should result in only one request being shown:
Unfortunately for us, the response only contains HTML. Also, API calls are protected - they require a PHP session ID and some sort of a token (__gsh) to not fail. So, going back to step 1 - seems like our only solution is to use regular expressions to find the text between "report_html":"<div class and </div></div></div> from the source code, if you're interested in today's date only. If you want to get contents for tomorrow or any other date - you will need to either fetch the page, save the cookies and find the token to supply to the request and then make that request, or use something like puppeteer or pyppeteer (since you've mentioned BS4) and load the webpage in that. If you aren't doing the data fetching that often, you should be fine overall.
I'm building an app where users can post comments. I would like to allow emojis within the comment text and so I have followed the steps in this article and also here to make sure the encoding within my app is utf8mb4 (which is needed for storing and displaying emojis).
Some steps I have taken are as follows:
I've set up my database with collation utf8mb4 and have specified a charset utf8mb4 in the DSN as follows:
"mysql:charset=utf8mb4"
After a comment is submitted, it gets stored into the database and I then retrieve it and insert it to the html.
This works perfect and the emojis are displaying in my app.
however I have also been taking measures to ensure XSS prevention in my app and so I have been using the OWASP ESAPI javascript library to encode any unsafe data before inserting it to the html.
So here is my "safe" code for displaying the comment text in the app (after it has come from the database)
var safe_comment_text_for_html = $ESAPI.encoder().encodeForHTML(comment_text);
var individual_comment_html = '<p class="text_of_comment">' + safe_comment_text_for_html + '</p>';
$('#comment_area').html(individual_comment_html);
Unfortunately this is causing the emojis to display as question marks.
Is there another OWASP encoding method I should use specifically for utf8mb4 or what would you advise I do, to display the emojis properly while also ensuring the data is safe before inserting to html? thanks
I have a registration form that asks the user for their start date. I am using a MEAN Framework which means Im using AngularJs on the front end.
What I have done so far:
First I tried using the following code BUT it does not work on IE & FireFox.
<input type="date" name="startDate">
Then I tried the following REGEX that I found on this SO question.
^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$
The works perfectly. Below is an image of how it works in my app.
The Issue:
When the user submits the form the data is saved in MongoDB. In the above image you can see that data is saved as a string. I want to convert it to a proper Date format so I can perform actions on it server side (Node.js) i.e filter all users who started after 2015 or left between 1999 & 2001 etc.
Any suggestions would be helpful.
UPDATE:
Currently I am testing moment.js. Will update my question once I have a result.
Result:
I tried the following using moment.js:
console.log("MOMENT" + moment("1993-03-25").format());
The output of the following was:
MOMENT 1993-03-25T00:00:00+00:00
I am not sure whether this is the correct format to be saved in MongoDB and will it allow me to perform server side actions on it.
You need to convert your moment object to a JavaScript date before you can save it MongoDB as a date field:
moment("1993-03-25").toDate()
I'm a relative newbie when it comes to coding, especially javascript. I currently am trying to populate a table from a google spreadsheet, which will update when the spreadsheet is.
I followed this tutorial word for word (basically all you need to do is replace the key with your own to specify your spreadsheet, and make sure its both published and public, which I've done)
http://dataforradicals.com/the-absurdly-illustrated-guide-to-sortable-searchable-online-data-tables/
I just get a bad request 400 error referring to my spreadsheet. If I visit the spreadsheet generated directly I just get the words...
"Invalid query parameter value for sq."
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&sq=&callback=Tabletop.callbacks.tt140241226993949106
I can visit my spreadsheet with the link I was given when I published it here..
[maximum links reached but the structure is different]
As you can see the domain structure is different. I fear that "Tabletop to Datatables" is adding an outdated url to the start of that link but can't find where it actually applies it.
The only reason I would think thats not happening is because the example in the tutorial still works! And the link it refers to is the old style URL too
I'm baffled, please help if you can. All suggestions appreciated
The query string includes a parameter without a value, &sq=.
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&sq=&callback=Tabletop.callbacks.tt140241226993949106
^^^^
Try this, with that parameter completely removed...
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&callback=Tabletop.callbacks.tt140241226993949106
There is an updated version of this project. Any necessary updates are included here:
https://github.com/scottpham/tabletop-to-datatables
Try with the updated versions of all js libraries.
Check the link and remove the extra string after pub. That part of link is not necessary and may cause issues.
According to google:
The 400 Bad Request error is an HTTP status code that means that the request you sent to the website server, often something simple like a request to load a web page, was somehow incorrect or corrupted and the server couldn't understand it.
Good luck