API surface
| Platform | Manager | Read | Enable | Disable |
|---|---|---|---|---|
| TypeScript | Client.notifications().community(communityId) | getSettings() | enable(events?) | disable() |
| iOS | communityRepository.notificationManager(forCommunityId:) | getSettings() | enable(events:) | disable() |
| Android | AmityCoreClient.notifications().community(communityId) | getSettings() | enable(eventModifiers?) | disable() |
| Flutter | AmityCoreClient.notifications().community(communityId) | getSettings() | enable(eventModifiers) | disable() |
Parameters
| Name | Platform | Type | Required | Description |
|---|---|---|---|---|
communityId | TypeScript, iOS, Android, Flutter | String / string | Yes | ID of the community whose push setting should be read or updated. |
events | TypeScript, iOS | Community notification event list | No on TypeScript, yes on iOS | Event-level modifiers to send with enable. |
eventModifiers | Android, Flutter | Community notification modifier list | No on Android, nullable on Flutter | Event-level modifiers to send with enable. |
roleFilter | TypeScript, iOS, Android, Flutter | Role filter | No | Optional filter for receiving notifications only from matching sender roles. |
Community events
| Event value | TypeScript enum | iOS case | Android modifier | Flutter modifier |
|---|---|---|---|---|
post.created | POST_CREATED | .postCreated | POST_CREATED | PostCreated |
post.reacted | POST_REACTED | .postReacted | POST_REACTED | PostReacted |
comment.created | COMMENT_CREATED | .commentCreated | COMMENT_CREATED | CommentCreated |
comment.replied | COMMENT_REPLIED | .commentReplied | COMMENT_REPLIED | CommentReplied |
comment.reacted | COMMENT_REACTED | .commentReacted | COMMENT_REACTED | CommentReacted |
story.created | STORY_CREATED | .storyCreated | STORY_CREATED | StoryCreated |
story.reacted | STORY_REACTED | .storyReacted | STORY_REACTED | StoryReacted |
story-comment.created | STORY_COMMENT_CREATED | .storyCommentCreated | STORY_COMMENT_CREATED | StoryCommentCreated |
video-streaming.didStart | LIVESTREAM_START | .livestreamStart | LIVESTREAM_START | Not exposed |
Flutter exposes
video-streaming as a user notification module, but this checkout does not expose a community-level livestream-start event modifier.Get community settings
Read community notification settings before rendering community-level or event-level push controls.import { Client } from '@amityco/ts-sdk';
const settings = await Client.notifications()
.community(communityId)
.getSettings();
const isEnabled = settings.isEnabled;
settings.events.forEach(event => {
const eventName = event.eventName;
const eventEnabled = event.isEnabled;
const networkEnabled = event.isNetworkEnabled;
updateUI({ eventName, eventEnabled, networkEnabled });
});
let notificationManager = communityRepository.notificationManager(forCommunityId: communityId)
let settings = try await notificationManager.getSettings()
let isEnabled = settings.isEnabled
for event in settings.events {
print("- event \(event.eventName) enabled: \(event.isEnabled)")
}
AmityCoreClient.notifications()
.community(communityId)
.getSettings()
.doOnSuccess { settings: AmityCommunityNotificationSettings ->
val isEnabled = settings.isEnabled()
settings.getNotificationEvents().forEach { event ->
when (event) {
is AmityCommunityNotificationEvent.POST_CREATED -> {
val eventEnabled = event.isEnabled()
val networkEnabled = event.isNetworkEnabled()
}
else -> Unit
}
}
}
.doOnError { error ->
// Handle error.
}
.subscribe()
final settings = await AmityCoreClient
.notifications()
.community(communityId)
.getSettings();
final isEnabled = settings.isEnabled;
settings.events?.forEach((event) {
final eventEnabled = event.isEnabled;
final networkEnabled = event.isNetworkEnabled;
});
Update community settings
Enable, disable, or customize community notification events after the user changes community push preferences.import {
Client,
CommunityNotificationEventNameEnum,
NotificationRolesFilterTypeEnum,
} from '@amityco/ts-sdk';
await Client.notifications()
.community(communityId)
.enable([
{
eventName: CommunityNotificationEventNameEnum.POST_CREATED,
isEnabled: true,
rolesFilter: {
type: NotificationRolesFilterTypeEnum.ONLY,
roleIds: ['community-moderator'],
},
},
{
eventName: CommunityNotificationEventNameEnum.STORY_REACTED,
isEnabled: false,
},
]);
await Client.notifications()
.community(communityId)
.disable();
let notificationManager = communityRepository.notificationManager(forCommunityId: communityId)
try await notificationManager.enable(events: [
AmityCommunityNotificationEvent(
eventType: .postCreated,
isEnabled: true,
roleFilter: AmityRoleFilter.onlyFilter(withRoleIds: ["community-moderator"])
),
AmityCommunityNotificationEvent(
eventType: .storyReacted,
isEnabled: false,
roleFilter: nil
),
])
try await notificationManager.disable()
val rolesFilter = AmityRolesFilter.ONLY(AmityRoles(listOf("community-moderator")))
val postCreatedModifier = AmityCommunityNotificationEvent.POST_CREATED.enable(rolesFilter)
val storyReactedModifier = AmityCommunityNotificationEvent.STORY_REACTED.disable()
AmityCoreClient.notifications()
.community(communityId)
.enable(
eventModifiers = listOf(
postCreatedModifier,
storyReactedModifier
)
)
.doOnComplete {
// Community notification settings updated.
}
.doOnError { error ->
// Handle error.
}
.subscribe()
AmityCoreClient.notifications()
.community(communityId)
.disable()
.subscribe()
final rolesFilter = Only(AmityRoles(roles: ['community-moderator']));
await AmityCoreClient
.notifications()
.community(communityId)
.enable([
PostCreated.enable(rolesFilter),
StoryReacted.disable(),
]);
await AmityCoreClient
.notifications()
.community(communityId)
.disable();
Related
User Settings
Configure account-wide push preferences and module modifiers.
Channel Settings
Configure push settings for a chat channel.