Hyvor Talk's main feature is the comments embed. It is a fully-featured real-time commenting system that can be embedded on blogs, news sites, and other websites.
The comments embed is loaded via the <hyvor-talk-comments>
Web Component. Go
get started, add the following script right before the </body>
tag. It
registers the
<hyvor-talk-comments>
Web Component on your webpage.
<script async src="https://talk.hyvor.com/embed/embed.js" type="module"></script>
Then, add the <hyvor-talk-comments>
element to the place where you want the comments
section to load. It is possible to add multiple comments sections to a single page if needed.
<hyvor-talk-comments
website-id="YOUR_WEBSITE_ID"
page-id=""
></hyvor-talk-comments>
The following attributes are supported in the <hyvor-talk-comments>
element
website-id
page-id
page-url
page-title
document.title
is used by default.page-language
page-author
sso-user
and sso-hash
colors
loading
settings
t-*
The page-id
attribute is used to identify the current page, and it is perhaps the most
important attribute.
Each page-id will load a different thread. It is highly recommended to use an ID that does not change over time (e.g. a database ID). If an ID change, you will need to migrate data to the new page manually. See our moving data between pages.
Instead of adding the <hyvor-talk-comments>
element directly to the HTML, you
can create it with JavaScript. This is useful when you need to use
properties.
const comments = document.createElement("hyvor-talk-comments");
comments.setAttribute("website-id", "YOUR_WEBSITE_ID");
comments.setAttribute('page-id', page.id);
document.body.appendChild(comments);
All website-level settings can be overridden at the page level using the settings
attribute. It accepts a JSON-encoded string. Here is an example:
<hyvor-talk-comments
website-id="x"
settings='{
"custom_css":"#app { font-size: 18px }",
"profiles": {
"pictures": false
}
}'
></hyvor-talk-comments>
Click the button below to see all available settings.
You can set custom translations using the t-
attributes.
<hyvor-talk-comments
t-as-guest="Comment without account"
t-newest="Latest"
/>
You can find the keys on the translation page
(login required). For example, if the key is as-guest
, the attribute should be
t-as-guest
. See language documentation for more information.
The settings
property does the same thing as the
settings
attribute. This is only supported for backward
compatibility.
Note that in order to make settings property work, you should wait until the Web Component is
defined. The easiest method is to use customElements.whenDefined
.
customElements.whenDefined('hyvor-talk-comments').then(() => {
// create the element
const comments = document.createElement("hyvor-talk-comments");
// set the settings
comments.settings = {}
// then append
document.getElementById("wrap").appendChild(comments);
});
This property is only supported for backward compatibility. We recommend using t- attributes for translations for new users.
const comments = document.createElement("hyvor-talk-comments");
comments.translations = {
sort: "Order by",
reactions_text: "What do you think about this post?",
}
By default, the comments section is loaded as soon as the commponent is added to the DOM. You
can customize this behavior using the loading
attribute. It accepts the following values:
default
- start loading immediatelylazy
- start loading when the element is in the viewport (using
IntersectionObserver)manual
- start loading when .load()
is called on the
<hyvor-talk-comments>
element.The loading
attribute can be set to manual
to delay the rendering of
the comments embed until the .load()
method is called. Here is an example with a button
to load the comments:
<hyvor-talk-comments
website-id="YOUR_WEBSITE_ID"
page-id=""
loading="manual"
></hyvor-talk-comments>
<button onclick="document.querySelector('hyvor-talk-comments').load()">Load Comments</button>
The <hyvor-talk-comments>
element exposes a mini-API with the following methods:
api.reload()
- reload the comments section. Same as
.load()
api.page()
- get current page data. See Page Object.api.auth.user()
- get the current user's public data. See
User Object. null
if not logged in.api.auth.logout()
- logout the current user. Removes the login storage from the
localStorage.Here is an example of how to get the current user's data:
const comments = document.querySelector("hyvor-talk-comments");
comments.api.auth.user();
interface Page {
id: number,
created_at: number,
identifier: string,
url: string,
title: string,
is_closed: boolean,
is_premoderation_on: boolean,
comments_count: number,
reactions: Record<'superb' | 'love' | 'wow' | 'sad' | 'laugh' | 'angry', number>,
ratings: {
average: number,
count: number
},
online_count: number
}
interface User {
id: number,
type: 'hyvor' | 'sso'
name: string,
username: string,
picture_url: string | null,
bio: string | null,
location: string | null,
website_url: string | null,
badges: number[]
}
The <hyvor-talk-comments>
element emits a few events that you can listen to. For
example, if a comment is published, you can use events to record it in your analytics service.
The following events are emitted:
loaded
- dispatched when the embed is fully loadedcomment:published
comment:edited
comment:deleted
comment:voted
comment:flagged
reaction
rating
auth:login:clicked
* - when the login button/link as clickedprofile:clicked
* - when the user's profile (name or profile picture) is clickedYou may call preventDefault()
on the event to prevent the default action in events
marked with *
.
Use addEventListener
on the <hyvor-talk-comments>
element.
const comments = document.querySelector("hyvor-talk-comments");
comments.addEventListener('comment:published', function (e) {
console.log("Comment ID: " + e.detail.id);
})
Here's a typescript definition of the all emitted events (event_name: data):
interface CommentsEvents {
'loaded': null,
'comment:published': RealComment,
'comment:edited': Comment,
'comment:deleted': Comment,
'comment:voted': {
comment: Comment,
vote: 'up' | 'down' | null
},
'comment:flagged': {
comment: Comment
},
'reaction': {
type: 'superb' | 'love' | 'wow' | 'sad' | 'laugh' | 'angry'
},
'rating': {
rating: number,
count: number,
average: number
},
'auth:login:clicked': null,
// when clicking on user's name or profile picture
'profile:clicked': User,
}
The Comment
object can be a HiddenComment
(ex: a deleted comment that
has replies) or a RealComment
.
interface BaseComment {
id: number,
page_id: number,
url: string,
parent_id: number | null,
depth: number,
created_at: number,
}
interface HiddenComment extends BaseComment {
is_hidden: true,
}
interface RealComment extends BaseComment {
is_hidden: false,
content: string
content_html: string,
is_featured: boolean,
is_loved: boolean,
is_edited: boolean,
upvotes: number,
downvotes: number,
user: User,
status: 'published' | 'spam' | 'deleted' | 'pending'
}
type Comment = HiddenComment | RealComment;
This documentation explains everything about commenting on a website that uses Hyvor Talk. If you are a website owner, you may share this document with your users.
Each website uses one of the following authentication methods:
While the login methods are different, both Hyvor and SSO users have access to the same features.
Hyvor Talk provides a Rich Text Editor for writing comments. This means that while most comments are text-based, commenters are able to add rich content like images, GIFs, and embeds to comments.
The following text styles are supported. Most styles support Markdown-style shortcuts.
Ctrl/⌘ + B
or **Text**
Ctrl/⌘ + I
or *Text*
~~Text~~
`Text`
!!Text!!
You can add links to your comment by using one of the following methods:
[Text](URL)
You can upload images and add them to your comment. The maximum image upload size is 2MB for Premium websites and 5MB for Business websites. PNG, JPEG/JPG, GIF, and WEBP formats are supported. Use one of the following methods to upload an image:
While you can upload GIFs from your computer as images, you can also search for GIFs easily and add them to your comments. Click the GIF icon below the comments box and search for the GIFs and add them. This feature is powered by Tenor.
Hyvor Talk supports embedding rich content from 1000+ platforms including Youtube, Twitter, Facebook, Linkedin, etc. To embed, click the Link button in the comments box, paste the URL, and choose “Embed”. If the link is not embeddable as rich content, it will be shown as a link preview (bookmark). This feature is powered by Iframely.
Type ```
in a new line to add a code block. Code blocks will be highlighted
autmatically using highlight.js.
You can mention other commenters. In the comments box, type @
to see suggestions. You
can only mention commenters who have published at least one comment on that website. The mentioned
user will receive an email notification with a link to your comment.
You can add math equations to your comments usingKaTeX. Type
$$
to start a math block. The math block will be rendered automatically.
You can block other users to hide their comments automatically in the future. They will also no longer see your comments. To block a user, first, open their user profile by clicking on their name or profile picture near their comment. Then, click the “Block User” button.
On each page, you can see the total number of online users on that page, which is updated as users join or leave the page. This online count is the total of logged-in and guest users. If the website has enabled it, you can also see who is online at a specific time on a page.
Moderators of the website can assign you up to 3 badges. These badges will be displayed alongside your name in your comments and the website profile.