Appearance
A conversation
Reached from the inbox or "New message".
Every example starts from saved, the checkpoint the index describes; the launch hands the feed, and a tab edge lands on the tab's root.
Open a conversation
ts
// Open a conversation from the inbox and read its messages.
const messages = await AndroidIgpapi.launch({
checkpoint: saved,
screen: FeedTimelineScreen,
main: feed =>
Effect.gen(function* () {
const tab = yield* feed.openDirectTab();
const item = tab.threads[0];
if (item === undefined) return [];
// The thread subscribes presence and loads the conversation.
const thread = yield* item.open();
return thread.messages.map(message => message.data.item_type);
}),
});
console.log(messages);Write a message
A message typed in a conversation: sendMessage(text).
ts
// Send a text message in a conversation of the inbox.
const sent = await AndroidIgpapi.launch({
checkpoint: saved,
screen: FeedTimelineScreen,
main: feed =>
Effect.gen(function* () {
const tab = yield* feed.openDirectTab();
const item = tab.threads[0];
if (item === undefined) return undefined;
const thread = yield* item.open();
return yield* thread.sendMessage('Hello from igpapi');
}),
});
console.log(sent);
A send that failed: your program gets a typed error (Errors).
The + menu (location, poll, images).
Send a photo from the gallery
The composer's "+" opened the gallery picker: openMediaPicker().
ts
// Send a photo: the composer's "+" opens the gallery picker, and the picked photo is sent.
const chosen = await readFile('photo.jpg');
const photoSent = await AndroidIgpapi.launch({
checkpoint: saved,
screen: FeedTimelineScreen,
main: feed =>
Effect.gen(function* () {
const tab = yield* feed.openDirectTab();
const item = tab.threads[0];
if (item === undefined) return undefined;
const thread = yield* item.open();
const picker = yield* thread.openMediaPicker();
if (!DirectMediaPickerPhotosScreen.is(picker)) return undefined;
return yield* picker.sendPhoto({ file: chosen });
}),
});
console.log(photoSent);The picker's own page is the gallery picker; a voice message, a GIF and a sticker are sent from the same composer.
Send a voice message
The composer before a voice message: the microphone in the field.
The voice message in the conversation after sendVoice({ file }).
ts
// Send a voice message: the composer's voice mode, with the take's own samples measured.
const take = await readFile('take.m4a');
const voice = await AndroidIgpapi.launch({
checkpoint: saved,
screen: FeedTimelineScreen,
main: feed =>
Effect.gen(function* () {
const tab = yield* feed.openDirectTab();
const item = tab.threads[0];
if (item === undefined) return undefined;
const thread = yield* item.open();
// The waveform is measured from the file; pass `waveform` to set the samples yourself.
return yield* thread.sendVoice({ file: take });
}),
});
console.log(voice);The message menu: react, reply, forward, edit, unsend
A message's long-press menu is its own actions. A double tap on a message sends nothing in the app, and the Simulator keeps that: the reaction is react.
The menu's types have a page each: a reply, an edited message and an unsent message.
A message's menu: reply, forward, edit and unsend on the message beside the reaction bar.
React
The tray: react({ emoji }) with one of its six emoji picked (❤, 😂, 😮, 😢, 😡, 👍); the tray's "+" is a super react and not modelled.

react({ emoji: '❤' }).

react({ emoji: '😂' }): every tray reaction is reaction_type=like with its emoji.
ts
// React to a message with the tray's heart.
const reacted = await AndroidIgpapi.launch({
checkpoint: saved,
screen: FeedTimelineScreen,
main: feed =>
Effect.gen(function* () {
const tab = yield* feed.openDirectTab();
const item = tab.threads[0];
if (item === undefined) return undefined;
const thread = yield* item.open();
const message = thread.messages[0];
if (message === undefined) return undefined;
return yield* message.react({ emoji: '❤' });
}),
});
console.log(reacted);Reply
Reply in a message's menu.

reply(text): the composer quotes the message.
The reply sent, quoting the message it answers.
ts
// Reply to the first message of a conversation.
const replied = await AndroidIgpapi.launch({
checkpoint: saved,
screen: FeedTimelineScreen,
main: feed =>
Effect.gen(function* () {
const tab = yield* feed.openDirectTab();
const item = tab.threads[0];
if (item === undefined) return undefined;
const thread = yield* item.open();
const message = thread.messages[0];
if (message === undefined) return undefined;
return yield* message.reply('Thanks!');
}),
});
console.log(replied);Forward
Forward in a message's menu.

forward() opens the forwarding sheet; the row's send() forwards and closes it.
ts
// Forward a message into another conversation the app holds.
const forwarded = await AndroidIgpapi.launch({
checkpoint: saved,
screen: FeedTimelineScreen,
main: feed =>
Effect.gen(function* () {
const tab = yield* feed.openDirectTab();
const item = tab.threads[0];
if (item === undefined) return undefined;
const thread = yield* item.open();
const message = thread.messages[0];
if (message === undefined) return undefined;
const sheet = yield* message.forward();
const target = sheet.threads[0];
if (target === undefined) return undefined;
// The send closes the sheet back to the conversation it came from.
return yield* target.send();
}),
});
console.log(forwarded);Edit
Edit in a message's menu.

edit(text): the composer carries the message's text.
The message after the edit.
The example edits the conversation's newest message. The library sends the edit for the message it names; Instagram decides whether it saves it, and a refusal is DirectEditMessageRejectedError.
ts
// Edit the conversation's newest message: `thread.messages` lists both sides.
const edited = await AndroidIgpapi.launch({
checkpoint: saved,
screen: FeedTimelineScreen,
main: feed =>
Effect.gen(function* () {
const tab = yield* feed.openDirectTab();
const item = tab.threads[0];
if (item === undefined) return undefined;
const thread = yield* item.open();
const message = thread.messages[0];
if (message === undefined) return undefined;
return yield* message.edit('The corrected text');
}),
});
console.log(edited);Unsend
Unsend in a message's menu.

unsend(): the app's confirmation.
The message gone from the conversation.
The example unsends the conversation's newest message. The library sends the unsend for the message it names; Instagram decides whether it removes the message, and a refusal is the core's RequestError.
ts
// Unsend the conversation's newest message: `thread.messages` lists both sides.
const unsent = await AndroidIgpapi.launch({
checkpoint: saved,
screen: FeedTimelineScreen,
main: feed =>
Effect.gen(function* () {
const tab = yield* feed.openDirectTab();
const item = tab.threads[0];
if (item === undefined) return undefined;
const thread = yield* item.open();
const message = thread.messages[0];
if (message === undefined) return undefined;
return yield* message.unsend();
}),
});
console.log(unsent);Write from a profile
ts
// Write to a person from their profile: the "Message" button opens the conversation.
const fromProfile = await AndroidIgpapi.launch({
checkpoint: saved,
screen: FeedTimelineScreen,
main: feed =>
Effect.gen(function* () {
const tab = yield* feed.openSearchTab();
let typed = yield* tab.openSearchInput();
typed = yield* typed.change('instagram');
const results = yield* typed.search('instagram');
const users = yield* results.openUsers();
const first = users.results[0];
if (first === undefined) return undefined;
const profile = yield* first.openProfile();
const thread = yield* profile.openDirectThread();
return yield* thread.sendMessage('Hi from your profile');
}),
});
console.log(fromProfile);