HTML to Simple Text

1,248 views
Skip to first unread message

George

unread,
Oct 24, 2021, 2:41:41 AM10/24/21
to Google Apps Script Community
All of the notifications coming out of my app currently are in HTML format. However I need to send some of the to Slack and it looks like Slack only accepts simple Text for these. So 2 questions for the group:

 1- Is there a way to send HTML formatted text to Slack?

 2- If answer to above is no, does anyone have a library that I can use to convert the simple HTML notifications to text?

 Thanks.

Tanaike

unread,
Oct 24, 2021, 4:40:07 AM10/24/21
to Google Apps Script Community
From this document, I thought that HTML might not be able to be directly used.

So, when you want to convert HTML to text data using Google Apps Script, how about the following script? When you use this script, please enable Drive API at Advanced Google services.

function myFunction() {
  const html = "###"; // Please set your HTML data.

  const id = Drive.Files.insert({title: "temp", mimeType: MimeType.GOOGLE_DOCS}, HtmlService.createHtmlOutput(html).getBlob()).id;
  const text = DocumentApp.openById(id).getBody().getText();
  DriveApp.getFileById(id).setTrashed(true);

  console.log(text) // You can retrieve the converted text data.
}


cbmserv...@gmail.com

unread,
Oct 24, 2021, 7:33:04 PM10/24/21
to google-apps-sc...@googlegroups.com

Thank you Tanaike. This worked perfectly for my purposes.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a1c0b2b7-9a4d-4e45-a9cb-4ba393e3fe82n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages