-
Notifications
You must be signed in to change notification settings - Fork 244
Direct messaging
Ramtin Jokar edited this page Sep 12, 2018
·
17 revisions
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:\\Files\\image1.jpg"
};
var directPhoto = await InstaApi.MessagingProcessor
.SendDirectPhotoAsync(image, requestedThreadId);
Note: only JPEG or JPG file will accept by instagram.
var directPhoto = await InstaApi.MessagingProcessor
.SendDirectPhotoToRecipientsAsync(image, "userId1", "userId2", "userId3", "....");
var directPhoto = await InstaApi.MessagingProcessor
.SendDirectDisappearingPhotoAsync(image, InstaViewMode.Replayable, requestedThreadId);
var video = new InstaVideo
{
// some video path
Uri = "C:\\Files\\video1.mp4"
};
var videoToUpload = new InstaVideoUpload
{
Video = video
};
var directVideo = await InstaApi.MessagingProcessor
.SendDirectVideoAsync(videoToUpload, requestedThreadId);
Note: only MP4 or MOV file will accept by instagram.
var directVideo = await InstaApi.MessagingProcessor
.SendDirectVideoToRecipientsAsync(videoToUpload, "userId1", "userId2", "userId3", "....");
var directVideo = await InstaApi.MessagingProcessor
.SendDirectDisappearingVideoAsync(videoToUpload, InstaViewMode.Replayable, requestedThreadId);
var link = "https://github.com/ramtinak/InstagramApiSharp";
var text = $"Hi, check this awesome instagram library for .net:\r\n{link}\r\nDon't forget to report issues!";
var directLink = await InstaApi.MessagingProcessor
.SendDirectLinkAsync(text, link, requestedThreadId);
// location information for Iran/Fars/Kazerun
double latitude = 29.61949;
double longitude = 51.65415;
var cityName = "Kazerun";
var locations = await InstaApi.LocationProcessor
.SearchLocationAsync(latitude, longitude, cityName);
var cityLocation = locations.Value.FirstOrDefault();
var cityExternalId = cityLocation.ExternalId;
var directLocation = await InstaApi.MessagingProcessor
.SendDirectLocationAsync(cityExternalId, requestedThreadId);
var user = await InstaApi.UserProcessor.GetUserAsync("rmt4006");
var userId = user.Value.Pk;
var directProfile = await InstaApi
.MessagingProcessor.SendDirectProfileAsync(userId, requestedThreadId);
You can check this quick sample: Direct messaging example class
Iranian Developers (c) 2021 | Bahar 1400