Appearance
Effects inside main
Most of what a person does has a screen, and the screen pages show it. A few things have none: a privacy setting, the authenticator key, mentions in a story, the followers of an account. The Simulator offers these as effects. You call them inside the main of an entry, on the process the entry already launched, so you never need a session file or the app layer for them.
How
Inside main, write yield* in front of the effect.
ts
import { AndroidIgpapi, FeedTimelineScreen, followersFeed, SettingsPrivacyMessagesGet } from '@igpapi/android';
import { Effect } from 'effect';
import { readFile } from 'node:fs/promises';
const saved = JSON.parse(await readFile('session.json', 'utf8'));
const result = await AndroidIgpapi.launch({
checkpoint: saved,
screen: FeedTimelineScreen,
main: _feed =>
Effect.gen(function* () {
// An effect with no screen runs inside `main`, on the process the entry already launched.
const settings = yield* SettingsPrivacyMessagesGet();
// A list is a feed: open it, then load its first page.
const followers = yield* followersFeed({ id: '123456' });
const page = yield* followers.next;
return { whoCanMessage: settings.ig_followers, followers: page.items.length };
}).pipe(
// These effects are not screen actions, so `otherwise` does not answer a challenge over them:
// the challenge stays their own error, and you decide what to do with it here.
Effect.catchTag('IgCheckpointError', () => Effect.succeed(undefined)),
),
});
console.log(result);SettingsPrivacyMessagesGet()reads who may message the account; the answer'sig_followersis the "Your followers on Instagram" setting.followersFeed({ id })opens the list;followers.nextloads one page and says whether there is more (Lists).- The process is launched already, so nothing more is needed: no
AndroidApp, no snapshot.
Challenges
A screen action that meets a challenge is answered by your otherwise branches, and the action runs again. These effects are not screen actions: a challenge over one of them stays its own error, IgCheckpointError. Answer it with Effect.catchTag('IgCheckpointError', …) as the program above does; the usual answer is to stop the program and let a person pass the challenge (Challenges).
The effects documented on this site
| You want to | Effect | Page |
|---|---|---|
| Read or change who can message the account | SettingsPrivacyMessagesGet, SettingsPrivacyMessagesSet | Message controls |
| Turn on the authenticator app | SecurityInfo, GenerateTwoFactorTotpKey, EnableTotpTwoFactor, AddKeyTotpTwoFactor | Turn on the authenticator app |
| Mention accounts in a story | MediaAddMentionedUser | Mention users in a story |
| Read followers and following | followersFeed and the other feeds | Lists |
| Send the telemetry now | FlushTelemetry | Telemetry |
When to use the app layer instead
When you need a request the Simulator has no effect for, or you run several programs over one process: Compose the app layer yourself.