Skip to content

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 conversationA 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 failed sendA send that failed: your program gets a typed error (Errors).

The + menuThe + menu (location, poll, images).

The gallery picker over the conversationThe 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 messageThe composer before a voice message: the microphone in the field.

The voice message in the conversationThe 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.

The message menu with the reaction barA message's menu: reply, forward, edit and unsend on the message beside the reaction bar.

React ​

The reaction tray over a messageThe tray: react({ emoji }) with one of its six emoji picked (❤, 😂, 😮, 😢, 😡, 👍); the tray's "+" is a super react and not modelled.

The heart on a messagereact({ emoji: '❤' }).

The laughing reactionreact({ 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 ​

The menu with ReplyReply in a message's menu.

The reply composer quoting the messagereply(text): the composer quotes the message.

The reply in the conversationThe 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 ​

The menu with ForwardForward in a message's menu.

The forwarding sheetforward() 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 ​

The menu with EditEdit in a message's menu.

The composer in edit modeedit(text): the composer carries the message's text.

The edited messageThe 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 ​

The menu with UnsendUnsend in a message's menu.

The Unsend confirmationunsend(): the app's confirmation.

The message goneThe 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);

The pages of this site are the README files of the repository. The API reference is generated from the source.