-
Notifications
You must be signed in to change notification settings - Fork 244
Direct messaging
Ramtin Jokar edited this page Sep 12, 2018
·
17 revisions
You can get inbox, get ranked recipients, send message and... Direct messaging example class
var inbox = await InstaApi.MessagingProcessor.GetDirectInboxAsync();
var firstThread = inbox.Value.Inbox.Threads.FirstOrDefault();
var requestedThreadId = firstThread.ThreadId;
var threads = await InstaApi.MessagingProcessor.GetDirectInboxThreadAsync(requestedThreadId);
var desireUsername = "rmt4006";
var desireThread = inbox.Value.Inbox.Threads.Find(u => u.Users.FirstOrDefault().UserName.ToLower() == desireUsername);
var requestedThreadId = desireThread.ThreadId;
var threads = await InstaApi.MessagingProcessor.GetDirectInboxThreadAsync(requestedThreadId);
var rankedRecipients = await InstaApi.MessagingProcessor.GetRankedRecipientsAsync();
var recentRecipients = await InstaApi.MessagingProcessor.GetRecentRecipientsAsync();
var pendingDirect = await InstaApi.MessagingProcessor.GetPendingDirectAsync();
var inbox = await InstaApi.MessagingProcessor.GetDirectInboxAsync();
var firstThread = inbox.Value.Inbox.Threads.FirstOrDefault();
var requestedThreadId = firstThread.ThreadId;
var directText = await InstaApi.MessagingProcessor.SendDirectTextAsync(null, requestedThreadId, "Hello Ramtin,\r\nHow are you today?");
var desireUsername = "rmt4006";
var user = await InstaApi.UserProcessor.GetUserAsync(desireUsername);
var userId = user.Value.Pk.ToString();
var directText = await InstaApi.MessagingProcessor.SendDirectTextAsync(userId, null, "Hello Ramtin,\r\nHow are you today?");
var userList = new List<string>();
// get user id(pk) for user 1
var user1 = await InstaApi.UserProcessor.GetUserAsync("rmt4006");
// add user id(pk) 1 to userList
userList.Add(user1.Value.Pk.ToString());
// get user id(pk) for user 2
var user2 = await InstaApi.UserProcessor.GetUserAsync("alingame");
// add user id(pk) 2 to userList
userList.Add(user2.Value.Pk.ToString());
// user ids must be splitted with comma character ,
var recipients = string.Join(",", userList);
// it should be something like this: userId1,userId2,userId3,userId3,....
// for current sample: 5318277344,719072853
var directText = await InstaApi.MessagingProcessor.SendDirectTextAsync(recipients, null, "Hello Ramtin,\r\nHow are you today?");
var image = new InstaImage
{
// some photo path
Uri = "C:\\Photos\\image1.jpg"
};
var directPhoto = await InstaApi.MessagingProcessor.SendDirectPhotoAsync(image, requestedThreadId);
Note: only JPEG or JPG file will accept by instagram
var image = new InstaImage
{
// some photo path
Uri = "C:\\Photos\\image1.jpg"
};
var directPhoto = await InstaApi.MessagingProcessor
.SendDirectDisappearingPhotoAsync(image, InstaViewMode.Replayable, requestedThreadId);
Iranian Developers (c) 2021 | Bahar 1400