import { DirectThreadEntity , IgApiClient } from '../src' ; import { promisify } from 'util' ; import { readFile } from 'fs' ; const readFileAsync = promisify ( readFile ) ; const ig = new IgApiClient ( ) ; async function login ( ) { ig . state . generateDevice ( process . env . IG_USERNAME ) ; ig . state . proxyUrl = process . env . IG_PROXY ; await ig . account . login ( process . env . IG_USERNAME , process . env . IG_PASSWORD ) ; } ( async ( ) => { await login ( ) ; const [ thread ] = await ig . feed . directInbox ( ) . records ( ) ; await sendPhoto ( thread ) ; await sendVideo ( thread ) ; await sendPhotoStory ( thread ) ; await sendVideoStory ( thread ) ; } ) ( ) ; param thread async function sendPhoto ( thread ) { const photo = await readFileAsync ( 'PATH_TO_PHOTO.jpg' ) ; console . log ( await thread . broadcastPhoto ( { file : photo , } ) ) ; } param thread async function sendVideo ( thread ) { const video = await readFileAsync ( 'PATH_TO_VIDEO.mp4' ) ; console . log ( await thread . broadcastVideo ( { video , transcodeDelay : 5 * 1000 , } ) ) ; } param thread async function sendVideoStory ( thread ) { const video = await readFileAsync ( 'PATH_TO_VIDEO.mp4' ) ; const cover = await readFileAsync ( 'PATH_TO_COVER.jpg' ) ; console . log ( await thread . broadcastStory ( { video , coverImage : cover , viewMode : 'replayable' , } ) ) ; } param thread async function sendPhotoStory ( thread ) { const photo = await readFileAsync ( 'PATH_TO_PHOTO.jpg' ) ; console . log ( await thread . broadcastStory ( { file : photo , viewMode : 'once' , } ) ) ; }