Skip to main content

External API

You can use the InAppStoryManager instance to consume the external API

import { InAppStoryManager } from "@inappstory/js-sdk"

const inAppStoryManagerConfig = {
apiKey: "{project-integration-key}",
};

const appearanceManager = new AppearanceManager();
const inAppStoryManager = new InAppStoryManager(inAppStoryManagerConfig)

Properties

PropertyTypeDescription
sdkVersionNamestringSDK version name (e.g., 3.7.0).
sdkVersionCodenumberNumeric SDK version code (e.g., 30700).
inAppMessagingInAppMessagingModule for displaying in-app messages.
storyLinkClickHandlerStoryLinkClickHandlerHandler for story link clicks. More details.

showOnboardingStories(appearanceManager, options?)

Displays onboarding stories.

inAppStoryManager.showOnboardingStories(appearanceManager, { feed: "main" })
.then(result => console.log(result.stories))
.catch(console.error);
  • Parameters:
    • options?: { feed?: string; customTags?: string[]; limit?: number }
    • appearanceManager: AppearanceManager
  • Returns: Promise<{ stories: { id: number; title: string }[] }>

showSharePage(storyId, appearanceManager)

Displays the share page for a specific story.

inAppStoryManager.showSharePage(123, appearanceManager).catch(console.error);
  • Parameters:
    • storyId: number | string
    • appearanceManager: AppearanceManager
  • Returns: Promise<void>

showStory(id, appearanceManager)

Displays a specific story.

inAppStoryManager.showStory(123, appearanceManager).catch(console.error);;
  • Parameters:
    • id: number | string
    • appearanceManager: AppearanceManager
  • Returns: Promise<void>

showStoryOnce(id, appearanceManager)

Displays a story only once.

inAppStoryManager.showStoryOnce(123, appearanceManager).catch(console.error);;
  • Parameters:
    • id: number | string
    • appearanceManager: AppearanceManager
  • Returns: Promise<void>

openGame(gameInstanceId, appearanceManager)

Opens a game by its instance ID.

inAppStoryManager.openGame("game-123", appearanceManager).catch(console.error);;
  • Parameters:
    • gameInstanceId: string | number
    • appearanceManager: AppearanceManager
  • Returns: Promise<void>

closeGame()

Closes the currently active game.

inAppStoryManager.closeGame().catch(console.error);
  • Returns: Promise<boolean>

closeStoryReader()

Closes the story view.

inAppStoryManager.closeStoryReader().catch(console.error);
  • Returns: Promise<boolean | undefined>

closeGoodsWidget()

Closes the goods widget V1.

inAppStoryManager.closeGoodsWidget();
  • Returns: void

setUserId(userId, sign?)

Set the user ID

inAppStoryManager.setUserId("new-user-id");
  • Parameters:
    • userId: string | number
    • sign?: string
  • Returns: void

userLogout()

Logs out the current user.

inAppStoryManager.userLogout().catch(console.error);
  • Returns: Promise<void>

setLang(lang)

Set the content language.

inAppStoryManager.setLang("en-US")
  • Parameters: lang: string
  • Returns: void

setTags(tags)

Set tags for filtering stories.

inAppStoryManager.setTags(["tag1", "tag2", "tagN"])
  • Parameters: tags: string[]
  • Returns: void

setPlaceholders(placeholders)

Set text placeholders.

inAppStoryManager.setPlaceholders({
"user-name": "Alex"
})
  • Parameters: placeholders: Record<string, string>
  • Returns: void

setPlaceholders(placeholders)

Set image placeholders.

inAppStoryManager.setImagePlaceholders({
"profile-photo": "https://example.com/images/user123.png"
})
  • Parameters: imagePlaceholders: Record<string, string>

  • Returns: void


on(eventName, listener)

Subscribes to an SDK events.

inAppStoryManager.on("showStory", (event) => {
console.log("Story opened:", event);
});
  • Parameters:

    • eventName: string
    • listener: (...args: any[]) => void
  • Returns: this