Repository: jomei/notionapi
Pull request #104 (2022-08-27 11:03:21)

Added support for Mention, Date and Equation in RichText object
RichText object can have other object types too like mention a page or a database or user or a date.
It can also have a inline equation.
Ref: https://developers.notion.com/reference/rich-text 

Sample json response for richtext having all the different objects mentioned in above link
```
{
    "object": "block",
    "id": "6c06b362-0000-4a9f-b70d-9181d1751957",
    "parent": {
        "type": "page_id",
        "page_id": "e50c7b3a-0000-4b26-a6f9-6dfef9f74148"
    },
    "created_time": "2022-08-27T07:16:00.000Z",
    "last_edited_time": "2022-08-27T10:42:00.000Z",
    "created_by": {
        "object": "user",
        "id": "00000000-545d-43c2-924e-f18a06fb93b3"
    },
    "last_edited_by": {
        "object": "user",
        "id": "00000000-545d-43c2-924e-f18a06fb93b3"
    },
    "has_children": false,
    "archived": false,
    "type": "paragraph",
    "paragraph": {
        "rich_text": [
            {
                "type": "mention",
                "mention": {
                    "type": "database",
                    "database": {
                        "id": "00000000-545d-43c2-924e-f18a06fb93b3"
                    }
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": "Test DB",
                "href": "https://www.notion.so/00000000510a4756b113cc28c7a30fd7"
            },
            {
                "type": "text",
                "text": {
                    "content": " ",
                    "link": null
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": " ",
                "href": null
            },
            {
                "type": "mention",
                "mention": {
                    "type": "page",
                    "page": {
                        "id": "00000000-545d-43c2-924e-f18a06fb93b3"
                    }
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": "Engineering Guidelines",
                "href": "https://www.notion.so/00000000df684670858ac632ebc2dd02"
            },
            {
                "type": "text",
                "text": {
                    "content": " ",
                    "link": null
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": " ",
                "href": null
            },
            {
                "type": "mention",
                "mention": {
                    "type": "user",
                    "user": {
                        "object": "user",
                        "id": "00000000-545d-43c2-924e-f18a06fb93b3",
                        "name": "Shivaji Sawant",
                        "avatar_url": null,
                        "type": "person",
                        "person": {
                            "email": "sawantshivaji1997@gmail.com"
                        }
                    }
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": "@Shivaji Sawant",
                "href": null
            },
            {
                "type": "text",
                "text": {
                    "content": " ",
                    "link": null
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": " ",
                "href": null
            },
            {
                "type": "mention",
                "mention": {
                    "type": "date",
                    "date": {
                        "start": "2022-08-27T03:00:00.000-07:00",
                        "end": "2022-08-27T03:00:00.000-07:00",
                        "time_zone": null
                    }
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": "2022-08-27T03:00:00.000-07:00 → 2022-08-27T03:00:00.000-07:00",
                "href": null
            },
            {
                "type": "text",
                "text": {
                    "content": " ",
                    "link": null
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": " ",
                "href": null
            },
            {
                "type": "equation",
                "equation": {
                    "expression": "Esd a"
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": "Esd a",
                "href": null
            },
            {
                "type": "text",
                "text": {
                    "content": " ",
                    "link": null
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": " ",
                "href": null
            }
        ],
        "color": "default"
    }
}
```

sawantshivaji1997: Thanks for the review. I will work on them.

Patch:
diff --git a/const.go b/const.go
index 9faee9f..c5577ac 100644
--- a/const.go
+++ b/const.go
@@ -242,3 +242,16 @@ const (
 	RollupTypeDate   RollupType = "date"
 	RollupTypeArray  RollupType = "array"
 )
+
+const (
+	MentionTypeDatabase        MentionType = "database"
+	MentionTypePage            MentionType = "page"
+	MentionTypeUser            MentionType = "user"
+	MentionTypeDate            MentionType = "date"
+	MentionTypeTemplateMention MentionType = "template_mention"
+)
+
+const (
+	TemplateMentionTypeUser TemplateMentionType = "template_mention_user"
+	TemplateMentionTypeDate TemplateMentionType = "template_mention_date"
+)
diff --git a/object.go b/object.go
index e644f3b..e3dc2e9 100644
--- a/object.go
+++ b/object.go
@@ -34,9 +34,46 @@ func (c Color) MarshalText() ([]byte, error) {
 	return []byte(c), nil
 }
 
+type MentionType string
+
+func (mType MentionType) String() string {
+	return string(mType)
+}
+
+type DatabaseMention struct {
+	ID ObjectID `json:"id"`
+}
+
+type PageMention struct {
+	ID ObjectID `json:"id"`
+}
+
+type TemplateMentionType string
+
+func (tMType TemplateMentionType) String() string {
+	return string(tMType)
+}
+
+type TemplateMention struct {
+	Type                TemplateMentionType `json:"type"`
+	TemplateMentionUser string              `json:"template_mention_user,omitempty"`
+	TemplateMentionDate string              `json:"template_mention_date,omitempty"`
+}
+
+type Mention struct {
+	Type            MentionType      `json:"type,omitempty"`
+	Database        *DatabaseMention `json:"database,omitempty"`
+	Page            *PageMention     `json:"page,omitempty"`
+	User            *User            `json:"user,omitempty"`
+	Date            *DateObject      `json:"date,omitempty"`
+	TemplateMention *TemplateMention `json:"template_mention,omitempty"`
+}
+
 type RichText struct {
 	Type        ObjectType   `json:"type,omitempty"`
-	Text        Text         `json:"text"`
+	Text        *Text        `json:"text,omitempty"`
+	Mention     *Mention     `json:"mention,omitempty"`
+	Equation    *Equation    `json:"equation,omitempty"`
 	Annotations *Annotations `json:"annotations,omitempty"`
 	PlainText   string       `json:"plain_text,omitempty"`
 	Href        string       `json:"href,omitempty"`


Test patch:
diff --git a/block_test.go b/block_test.go
index 732c7af..dcb7f3f 100644
--- a/block_test.go
+++ b/block_test.go
@@ -84,7 +84,7 @@ func TestBlockClient(t *testing.T) {
 							}{[]notionapi.RichText{
 								{
 									Type: notionapi.ObjectTypeText,
-									Text: notionapi.Text{Content: "Hello"},
+									Text: &notionapi.Text{Content: "Hello"},
 								},
 							}, nil, "",
 							},
@@ -114,7 +114,7 @@ func TestBlockClient(t *testing.T) {
 								RichText: []notionapi.RichText{
 									{
 										Type: notionapi.ObjectTypeText,
-										Text: notionapi.Text{Content: "AAAAAA"},
+										Text: &notionapi.Text{Content: "AAAAAA"},
 										Annotations: &notionapi.Annotations{
 											Bold:  true,
 											Color: notionapi.ColorDefault,
@@ -237,7 +237,7 @@ func TestBlockClient(t *testing.T) {
 					Paragraph: &notionapi.Paragraph{
 						RichText: []notionapi.RichText{
 							{
-								Text: notionapi.Text{Content: "Hello"},
+								Text: &notionapi.Text{Content: "Hello"},
 							},
 						},
 						Color: notionapi.ColorYellow.String(),
@@ -255,7 +255,7 @@ func TestBlockClient(t *testing.T) {
 						RichText: []notionapi.RichText{
 							{
 								Type: notionapi.ObjectTypeText,
-								Text: notionapi.Text{
+								Text: &notionapi.Text{
 									Content: "Hello",
 								},
 								Annotations: &notionapi.Annotations{Color: notionapi.ColorDefault},
@@ -325,7 +325,7 @@ func TestBlockArrayUnmarshal(t *testing.T) {
 							RichText: []notionapi.RichText{
 								{
 									Type: "text",
-									Text: notionapi.Text{
+									Text: &notionapi.Text{
 										Content: "This page is designed to be shared with students on the web. Click ",
 									},
 									Annotations: &notionapi.Annotations{
@@ -334,7 +334,7 @@ func TestBlockArrayUnmarshal(t *testing.T) {
 									PlainText: "This page is designed to be shared with students on the web. Click ",
 								}, {
 									Type: "text",
-									Text: notionapi.Text{
+									Text: &notionapi.Text{
 										Content: "Share",
 									},
 									Annotations: &notionapi.Annotations{
@@ -365,7 +365,7 @@ func TestBlockArrayUnmarshal(t *testing.T) {
 							RichText: []notionapi.RichText{
 								{
 									Type: "text",
-									Text: notionapi.Text{
+									Text: &notionapi.Text{
 										Content: "History 340",
 									},
 									Annotations: &notionapi.Annotations{
@@ -419,7 +419,7 @@ func TestBlockArrayUnmarshal(t *testing.T) {
 							RichText: []notionapi.RichText{
 								{
 									Type: "text",
-									Text: notionapi.Text{
+									Text: &notionapi.Text{
 										Content: "Assignment Submission",
 									},
 									Annotations: &notionapi.Annotations{
@@ -446,7 +446,7 @@ func TestBlockArrayUnmarshal(t *testing.T) {
 							RichText: []notionapi.RichText{
 								{
 									Type: "text",
-									Text: notionapi.Text{
+									Text: &notionapi.Text{
 										Content: "All essays and papers are due in lecture (due dates are listed on the schedule). No electronic copies will be accepted!",
 									},
 									Annotations: &notionapi.Annotations{
diff --git a/database_test.go b/database_test.go
index edf7ac4..03f7e12 100644
--- a/database_test.go
+++ b/database_test.go
@@ -46,7 +46,7 @@ func TestDatabaseClient(t *testing.T) {
 					Title: []notionapi.RichText{
 						{
 							Type:        notionapi.ObjectTypeText,
-							Text:        notionapi.Text{Content: "Test Database"},
+							Text:        &notionapi.Text{Content: "Test Database"},
 							Annotations: &notionapi.Annotations{Color: "default"},
 							PlainText:   "Test Database",
 							Href:        "",
@@ -178,7 +178,7 @@ func TestDatabaseClient(t *testing.T) {
 					Title: []notionapi.RichText{
 						{
 							Type: notionapi.ObjectTypeText,
-							Text: notionapi.Text{Content: "patch"},
+							Text: &notionapi.Text{Content: "patch"},
 						},
 					},
 					Properties: notionapi.PropertyConfigs{
@@ -201,7 +201,7 @@ func TestDatabaseClient(t *testing.T) {
 					Title: []notionapi.RichText{
 						{
 							Type: notionapi.ObjectTypeText,
-							Text: notionapi.Text{Content: "patch"},
+							Text: &notionapi.Text{Content: "patch"},
 						},
 					},
 				},
@@ -248,7 +248,7 @@ func TestDatabaseClient(t *testing.T) {
 					Title: []notionapi.RichText{
 						{
 							Type: notionapi.ObjectTypeText,
-							Text: notionapi.Text{Content: "Grocery List"},
+							Text: &notionapi.Text{Content: "Grocery List"},
 						},
 					},
 					Properties: notionapi.PropertyConfigs{
@@ -271,7 +271,7 @@ func TestDatabaseClient(t *testing.T) {
 					Title: []notionapi.RichText{
 						{
 							Type:        notionapi.ObjectTypeText,
-							Text:        notionapi.Text{Content: "Grocery List"},
+							Text:        &notionapi.Text{Content: "Grocery List"},
 							PlainText:   "Grocery List",
 							Annotations: &notionapi.Annotations{Color: notionapi.ColorDefault},
 						},
diff --git a/page_test.go b/page_test.go
index 8833ac8..9a91937 100644
--- a/page_test.go
+++ b/page_test.go
@@ -85,7 +85,7 @@ func TestPageClient(t *testing.T) {
 							RichText: []notionapi.RichText{
 								{
 									Type: "text",
-									Text: notionapi.Text{
+									Text: &notionapi.Text{
 										Content: "some text",
 									},
 									Annotations: &notionapi.Annotations{
@@ -114,7 +114,7 @@ func TestPageClient(t *testing.T) {
 							Title: []notionapi.RichText{
 								{
 									Type: "text",
-									Text: notionapi.Text{
+									Text: &notionapi.Text{
 										Content: "Hello",
 									},
 									Annotations: &notionapi.Annotations{
@@ -207,7 +207,7 @@ func TestPageClient(t *testing.T) {
 					Properties: notionapi.Properties{
 						"Name": notionapi.TitleProperty{
 							Title: []notionapi.RichText{
-								{Text: notionapi.Text{Content: "hello"}},
+								{Text: &notionapi.Text{Content: "hello"}},
 							},
 						},
 					},
@@ -276,7 +276,7 @@ func TestPageClient(t *testing.T) {
 							RichText: []notionapi.RichText{
 								{
 									Type: notionapi.ObjectTypeText,
-									Text: notionapi.Text{Content: "patch"},
+									Text: &notionapi.Text{Content: "patch"},
 								},
 							},
 						},
@@ -372,7 +372,7 @@ func TestPageCreateRequest_MarshallJSON(t *testing.T) {
 					},
 					"Name": notionapi.TitleProperty{
 						Title: []notionapi.RichText{
-							{Text: notionapi.Text{Content: "New Media Article"}},
+							{Text: &notionapi.Text{Content: "New Media Article"}},
 						},
 					},
 					"Publishing/Release Date": notionapi.DateProperty{
@@ -387,7 +387,7 @@ func TestPageCreateRequest_MarshallJSON(t *testing.T) {
 						Text: []notionapi.RichText{
 							{
 								Type: notionapi.ObjectTypeText,
-								Text: notionapi.Text{
+								Text: &notionapi.Text{
 									Content: "Some content",
 								},
 								Annotations: &notionapi.Annotations{
@@ -421,7 +421,7 @@ func TestPageCreateRequest_MarshallJSON(t *testing.T) {
 					},
 					"Name": notionapi.TitleProperty{
 						Title: []notionapi.RichText{
-							{Text: notionapi.Text{Content: "New Media Article"}},
+							{Text: &notionapi.Text{Content: "New Media Article"}},
 						},
 					},
 					"Publishing/Release Date": notionapi.DateProperty{
@@ -436,7 +436,7 @@ func TestPageCreateRequest_MarshallJSON(t *testing.T) {
 						Text: []notionapi.RichText{
 							{
 								Type: notionapi.ObjectTypeText,
-								Text: notionapi.Text{
+								Text: &notionapi.Text{
 									Content: "Some content",
 								},
 								Annotations: &notionapi.Annotations{
@@ -461,7 +461,7 @@ func TestPageCreateRequest_MarshallJSON(t *testing.T) {
 							RichText: []notionapi.RichText{
 								{
 									Type: notionapi.ObjectTypeText,
-									Text: notionapi.Text{Content: "Lacinato"},
+									Text: &notionapi.Text{Content: "Lacinato"},
 								},
 							},
 						},
@@ -474,7 +474,7 @@ func TestPageCreateRequest_MarshallJSON(t *testing.T) {
 						Paragraph: notionapi.Paragraph{
 							RichText: []notionapi.RichText{
 								{
-									Text: notionapi.Text{
+									Text: &notionapi.Text{
 										Content: "Lacinato",
 										Link: &notionapi.Link{
 											Url: "some_url",