Skip to main content

๐Ÿ›„ Migrating Messages Between Slate Instances

Is it possible to move messages from one Slate instance to another? ๐Ÿค”

No, you can't import directly to theย [message] table, but you can import interactions, which will also appear on the timeline. The typical issue with this approach is that message bodies are unreadable HTML.

Using Python and html2text, one can convert the HTML message bodies into Markdown format, which is simple enough to be read by humans.

Export messages as CSV, being sure to includeย [message].[body]. Your body column should be namedย Message Body.

Save the file, update the .csv filename in this Python script, and run the script. Presto, readable messages!

import html2text
import csv

h = html2text.HTML2Text()
# h.body_width = 48  # Wrap lines
h.protect_links = True  # True means don't put linebreaks in links
h.ignore_images = True  # True off if you want to see stuff like ![](https://apply.school.edu/www/images/Marketing%20Photo%20Christmas.png)
h.ignore_emphasis = False # Mark bold, italics, etc.?

# Update this to the name of your CSV file
input_file = "Messages-Export.csv"

# Open CSV
with open(input_file, "r", encoding="utf-8-sig") as csvfile:
    fname = csvfile.name[:-4]
    converted_fname = fname + "_converted.csv"

    # Save a new CSV with the message body converted to Markdown
    with open(converted_fname, "w", encoding="utf-8-sig") as csvconverted:
        reader = csv.DictReader(csvfile)
        writer = csv.DictWriter(csvconverted, fieldnames=reader.fieldnames)
        writer.writeheader()
        for row in reader:
            row["Message Body"] = h.handle(row["Message Body"])
            writer.writerow(row)