Skip to main content
Version: Next

ModMailService

@devvit/reddit v0.15.7-dev


Class: ModMailService

Class providing the methods for working with Mod Mail

Properties​

notificationSubjectPrefix​

readonly notificationSubjectPrefix: "[notification]" = '[notification]'

Methods​

approveConversation()​

approveConversation(conversationId): Promise<ConversationResponse & WithUserData>

Approve the non mod user associated with a particular conversation.

Parameters​

conversationId​

string

Id of a modmail conversation

Returns​

Promise<ConversationResponse & WithUserData>

Example​

await reddit.modMail.approveConversation('abcdef');

archiveConversation()​

archiveConversation(conversationId): Promise<ConversationResponse>

Marks a conversation as archived

Parameters​

conversationId​

string

Id of a modmail conversation

Returns​

Promise<ConversationResponse>

Example​

await reddit.modMail.archive('abcdef');

bulkReadConversations()​

bulkReadConversations(subreddits, state): Promise<string[]>

Marks all conversations read for a particular conversation state within the passed list of subreddits.

Parameters​

subreddits​

string[]

Array of subreddit names

state​

ConversationStateFilter

One of the possible conversation states ('all' to read all conversations)

Returns​

Promise<string[]>

conversationIds

Example​

const conversationIds = await reddit.modMail.bulkReadConversations(
['askReddit', 'myAwesomeSubreddit'],
'filtered'
);

createConversation()​

createConversation(params): Promise<ConversationResponse & WithUserData>

Creates a new conversation for a particular SR.

This endpoint will create a ModmailConversation object as well as the first ModmailMessage within the ModmailConversation object.

Parameters​

params​
body​

string

markdown text

isAuthorHidden?​

boolean

is author hidden? (default: false)

subject​

string

subject of the conversation. max 100 characters

subredditName​

string

subreddit name

to?​

string | null

a user (e.g. u/username), a subreddit (e.g. r/subreddit) or null

Returns​

Promise<ConversationResponse & WithUserData>

Note​

Note on {param.to}: The to field for this endpoint is somewhat confusing. It can be:

  • A User, passed like "username" or "u/username"
  • A Subreddit, passed like "r/subreddit"
  • null, meaning an internal moderator discussion

In this way to is a bit of a misnomer in modmail conversations. What it really means is the participant of the conversation who is not a mod of the subreddit.

If you plan to send a message to the app-account or a moderator of the subreddit, use ModMailService.createModDiscussionConversation, ModMailService.createModInboxConversation, or ModMailService.createModNotification instead. Otherwise, messages sent to the app-account or moderator will automatically be routed to Mod Discussions.

Example​

const { conversation, messages, modActions } = await reddit.modMail.createConversation({
subredditName: 'askReddit',
subject: 'Test conversation',
body: 'Lorem ipsum sit amet',
to: null,
});

createModDiscussionConversation()​

createModDiscussionConversation(params): Promise<string>

Creates a conversation in Mod Discussions with the moderators of the given subredditId.

Note: The app must be installed in the subreddit in order to create a conversation in Mod Discussions.

Parameters​

params​
bodyMarkdown​

string

The body of the message in Markdown format, e.g. Hello world \n\n **Have a great day**.

subject​

string

The subject of the message.

subredditId​

`t5_${string}`

The ID (starting with t5_) of the subreddit to which to send the message, e.g. t5_2qjpg.

Returns​

Promise<string>

A Promise that resolves a string representing the conversationId of the message.

Example​

const conversationId = await reddit.modMail.createModDiscussionConversation({
subject: 'Test conversation',
bodyMarkdown: '**Hello there** \n\n _Have a great day!_',
subredditId: context.subredditId
});

createModInboxConversation()​

createModInboxConversation(params): Promise<string>

Creates a conversation in the Modmail Inbox with the moderators of the given subredditId.

Parameters​

params​
bodyMarkdown​

string

The body of the message in Markdown format, e.g. Hello world \n\n **Have a great day**.

subject​

string

The subject of the message.

subredditId​

`t5_${string}`

The ID (starting with t5_) of the subreddit to which to send the message, e.g. t5_2qjpg.

Returns​

Promise<string>

A Promise that resolves a string representing the conversationId of the message.

Example​

const conversationId = await reddit.modMail.createModInboxConversation({
subject: 'Test conversation',
bodyMarkdown: '**Hello there** \n\n _Have a great day!_',
subredditId: context.subredditId
});

createModNotification()​

createModNotification(params): Promise<string>

Creates a notification in the Modmail Inbox. This function is different from ModMailService.createModInboxConversation in that the conversation also appears in the "Notifications" section of Modmail.

Parameters​

params​
bodyMarkdown​

string

The body of the message in Markdown format, e.g. Hello world \n\n **Have a great day**.

subject​

string

The subject of the message.

subredditId​

`t5_${string}`

The ID (starting with t5_) of the subreddit to which to send the message, e.g. t5_2qjpg.

Returns​

Promise<string>

A Promise that resolves a string representing the conversationId of the message.

Example​

const conversationId = await reddit.modMail.createModNotification({
subject: 'Test notification',
bodyMarkdown: '**Hello there** \n\n _This is a notification!_',
subredditId: context.subredditId
});

disapproveConversation()​

disapproveConversation(conversationId): Promise<ConversationResponse & WithUserData>

Disapprove the non mod user associated with a particular conversation.

Parameters​

conversationId​

string

Id of a modmail conversation

Returns​

Promise<ConversationResponse & WithUserData>

Example​

await reddit.modMail.disapproveConversation('abcdef');

getConversation()​

getConversation(params): Promise<GetConversationResponse>

Returns all messages, mod actions and conversation metadata for a given conversation id

Parameters​

params​
conversationId​

string

a modmail conversation id

markRead?​

boolean

mark read?

Returns​

Promise<GetConversationResponse>

Example​

const { conversation, messages, modActions, user } = await reddit.modMail.getConversation({ conversationId: 'abcdef', markRead: true });

getConversations()​

getConversations(params): Promise<GetConversationsResponse>

Get conversations for a logged in user or subreddits

Parameters​

params​

GetConversationsRequest

Returns​

Promise<GetConversationsResponse>

Example​

const {viewerId, conversations} = await reddit.modMail.getConversations({
after: 'abcdef',
limit: 42
});

const arrayOfConversations = Object.values(conversations);

getSubreddits()​

getSubreddits(): Promise<{[key: string]: SubredditData; }>

Returns a list of Subreddits that the user moderates with mail permission

Returns​

Promise<{[key: string]: SubredditData; }>

Example​

const subredditsData = await reddit.modMail.getSubreddits();

for (const subreddit of Object.values(subreddits)) {
console.log(subreddit.id);
console.log(subreddit.name);
}

getUnreadCount()​

getUnreadCount(): Promise<UnreadCountResponse>

Endpoint to retrieve the unread conversation count by conversation state.

Returns​

Promise<UnreadCountResponse>

Example​

const response = await reddit.modMail.getUnreadCount();

console.log(response.highlighted);
console.log(response.new);

getUserConversations()​

getUserConversations(conversationId): Promise<ConversationUserData>

Returns account and moderation information for the user participant of a modmail conversation, including their recent posts, comments, and modmail conversations in the same subreddit.

Parameters​

conversationId​

string

ID of a modmail conversation with a user participant.

Returns​

Promise<ConversationUserData>

Throws​

If the conversation does not have a user participant.

Example​

const data = await reddit.modMail.getUserConversations('abcdef');

console.log(data.recentComments);
console.log(data.recentPosts);

highlightConversation()​

highlightConversation(conversationId): Promise<ConversationResponse>

Marks a conversation as highlighted.

Parameters​

conversationId​

string

Id of a modmail conversation

Returns​

Promise<ConversationResponse>

Example​

await reddit.modMail.highlightConversation('abcdef');

muteConversation()​

muteConversation(params): Promise<ConversationResponse & WithUserData>

Marks a conversation as read for the user.

Parameters​

params​
conversationId​

string

Id of a modmail conversation

numHours​

72 | 168 | 672

For how many hours the conversation needs to be muted. Must be one of 72, 168, or 672 hours

Returns​

Promise<ConversationResponse & WithUserData>

Example​

await reddit.modMail.muteConversation({ conversationId: 'abcdef', numHours: 72 });

readConversations()​

readConversations(conversationIds): Promise<void>

Marks a conversations as read for the user.

Parameters​

conversationIds​

string[]

An array of ids

Returns​

Promise<void>

Example​

await reddit.modMail.readConversations(['abcdef', 'qwerty']);

reply()​

reply(params): Promise<ConversationResponse & WithUserData>

Creates a new message for a particular conversation.

Parameters​

params​
body​

string

markdown text

conversationId​

string

Id of a modmail conversation

isAuthorHidden?​

boolean

is author hidden? (default: false)

isInternal?​

boolean

is internal message? (default: false)

Returns​

Promise<ConversationResponse & WithUserData>

Example​

await reddit.modMail.reply({
body: 'Lorem ipsum sit amet',
conversationId: 'abcdef',
});

tempBanConversation()​

tempBanConversation(params): Promise<ConversationResponse & WithUserData>

Temporary ban (switch from permanent to temporary ban) the non mod user associated with a particular conversation.

Parameters​

params​
conversationId​

string

a modmail conversation id

duration​

number

duration in days, max 999

Returns​

Promise<ConversationResponse & WithUserData>

Example​

await reddit.modMail.tempBanConversation({ conversationId: 'abcdef', duration: 42 });

unarchiveConversation()​

unarchiveConversation(conversationId): Promise<ConversationResponse>

Marks conversation as unarchived.

Parameters​

conversationId​

string

Id of a modmail conversation

Returns​

Promise<ConversationResponse>

Example​

await reddit.modMail.unarchiveConversation('abcdef');

unbanConversation()​

unbanConversation(conversationId): Promise<ConversationResponse & WithUserData>

Unban the non mod user associated with a particular conversation.

Parameters​

conversationId​

string

a modmail conversation id

Returns​

Promise<ConversationResponse & WithUserData>

Example​

await reddit.modMail.unbanConversation('abcdef');

unhighlightConversation()​

unhighlightConversation(conversationId): Promise<ConversationResponse>

Removes a highlight from a conversation.

Parameters​

conversationId​

string

Id of a modmail conversation

Returns​

Promise<ConversationResponse>

Example​

await reddit.modMail.unhighlightConversation('abcdef');

unmuteConversation()​

unmuteConversation(conversationId): Promise<ConversationResponse & WithUserData>

Unmutes the non mod user associated with a particular conversation.

Parameters​

conversationId​

string

Id of a modmail conversation

Returns​

Promise<ConversationResponse & WithUserData>

Example​

await reddit.modMail.unmuteConversation('abcdef');

unreadConversations()​

unreadConversations(conversationIds): Promise<void>

Marks conversations as unread for the user.

Parameters​

conversationIds​

string[]

An array of ids

Returns​

Promise<void>

Example​

await reddit.modMail.unreadConversations(['abcdef', 'qwerty']);