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

Export plaintext message content in JSON text field #26295

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

shaunnope
Copy link

Related Problem
As of v4.8.1, when exporting chats as JSON, the text fields of messages has two return types:

  1. string if message is entirely in plain text, with no message entities
  2. array of mixed types otherwise (string for plain text, object for styled text)

This was first identified in #25000.

Consider the following message:

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Morbi lobortis lacus eget leo iaculis maximus.

The text field of the resulting JSON export for the message is

"text": [
    "Lorem ipsum dolor sit",
    {
     "type": "bold",
     "text": " amet, consectetur"
    },
    " ",
    {
     "type": "italic",
     "text": "adipiscing elit"
    },
    ".\n",
    {
     "type": "code",
     "text": "Morbi lobortis"
    },
    " lacus eget leo iaculis maximus."
   ],

Proposed Solution
Concatenate the plaintext content for all message entities, producing a single string for the text field.

For example, the text and text_entity fields for message above would be exported as

{
   "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nMorbi lobortis lacus eget leo iaculis maximus.",
   "text_entities": [
    {
     "type": "plain",
     "text": "Lorem ipsum dolor sit"
    },
    {
     "type": "bold",
     "text": " amet, consectetur"
    },
    {
     "type": "plain",
     "text": " "
    },
    {
     "type": "italic",
     "text": "adipiscing elit"
    },
    {
     "type": "plain",
     "text": ".\n"
    },
    {
     "type": "code",
     "text": "Morbi lobortis"
    },
    {
     "type": "plain",
     "text": " lacus eget leo iaculis maximus."
    }
   ]
  }

This behaviour is also in keeping with the Telegram API and Bot API, where Message objects have message and text fields respectively for storing the plaintext content of a message.

@CLAassistant
Copy link

CLAassistant commented May 14, 2023

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants