/// <summary> /// 사용자에게 메시지를 보낸다. /// </summary> /// <param name="ctype">조회 할 필드</param> /// <param name="info">조회 할 정보</param> /// <param name="msg">보낼 메시지</param> /// <returns></returns> public async Task SendMessageByContacts(enContactInfoType ctype, string info, string msg) { //인증 확인 isAuth(true); //연락처 조회전이면 조회 한다. if (_contacts == null) { await ContactsGet(); } DataRow[] rows = await UserInfoGetFromContact(ctype, info); if (rows.Length < 1 || info == null || info.Trim().Equals(string.Empty)) { throw new Exception(string.Format("[Type]{0} [Info]{1} 로 연락처 정보를 찾을 수 없습니다.", ctype, info)); } foreach (DataRow dr in rows) { await client.SendMessageAsync(new TLInputPeerUser() { user_id = Fnc.obj2int(dr["id"]) }, msg); } }
protected async System.Threading.Tasks.Task SendMessaggioTelegram(string numeroTelefono, string code, string messaggio) { var client = new TLSharp.Core.TelegramClient(106191, "2a5c0da8fcb3acfdf501c3f17fb0fa5f"); await client.ConnectAsync(); var hash = await client.SendCodeRequestAsync(numeroTelefono); var user = await client.MakeAuthAsync(numeroTelefono, hash, code); //get available contacts var result = await client.GetContactsAsync(); //find recipient in contacts var customer = result.Users .Where(x => x.GetType() == typeof(TeleSharp.TL.TLUser)) .Cast <TeleSharp.TL.TLUser>() .FirstOrDefault(x => x.Phone == numeroTelefono); /*if (user.ToList().Count != 0) * { * foreach (var u in user) * { * if (u.phone.Contains("3965604")) * { * //send message * await client.SendMessageAsync(new TLInputPeerUser() { user_id = u.id }, textBox3.Text); * } * } * }*/ // @channelname or chat_id, messaggio da inviare await client.SendMessageAsync(new TeleSharp.TL.TLInputPeerUser() { UserId = customer.Id }, messaggio); }
public virtual async Task SendMessageToUser(string toUserName, string message) { var client = new TLSharp.Core.TelegramClient(apiId, apiHash); await client.ConnectAsync(); var normalizedUser = (toUserName.StartsWith("@") ? toUserName.Substring(1, toUserName.Length - 1) : toUserName).ToLower(); var dialogs = (TLDialogs)await client.GetUserDialogsAsync(); var user = dialogs.Users .Where(x => x.GetType() == typeof(TLUser)) .OfType <TLUser>() .FirstOrDefault(x => x.Username != null && x.Username.ToLower() == normalizedUser); if (user != null) { await client.SendTypingAsync(new TLInputPeerUser() { UserId = user.Id, AccessHash = user.AccessHash.Value }); await client.SendMessageAsync(new TLInputPeerUser() { UserId = user.Id, AccessHash = user.AccessHash.Value }, message); } //await client.SendMessageAsync(new TLInputPeerUser() { UserId = user.Id, AccessHash = user.AccessHash.Value }, message); //send message //await client.SendMessageAsync(new TLInputPeerChannel() { ChannelId = chat.Id, AccessHash = chat.AccessHash.Value }, "OUR_MESSAGE"); //var result = await client.SearchUserAsync(normalizedUser, 10); //if (result.Users.Count > 0) //{ // TLUser user = (TLUser)result.Users[0]; // await client.SendMessageAsync(new TLInputPeerUser() { UserId = user.Id }, message); //} //var normalizedNumber1 = toUserName.StartsWith("@") ? // toUserName.Substring(1, toUserName.Length - 1) : // toUserName; //var user = result.Users // .OfType<TLUser>() // .FirstOrDefault(x => x.Username == toUserName); //await client.SendMessageAsync(new TLInputPeerUser() { UserId = user.Id }, message); }
/// <summary> /// 전화 번호로 /// </summary> /// <param name="client"></param> /// <param name="PhoneNumber"></param> /// <param name="msg"></param> private async void SendMessageByPhoneNumber(TLSharp.Core.TelegramClient client, string PhoneNumber, string msg) { //연락처를 받아 온다 var rst = await client.GetContactsAsync(); //사용자를 찾는다. var usr = rst.users.lists .Where(x => x.GetType() == typeof(TLUser)) .Cast <TLUser>() .FirstOrDefault(x => x.phone.EndsWith(PhoneNumber)); TLUser tl; await client.SendMessageAsync(new TLInputPeerUser() { user_id = usr.id }, msg); }
public virtual async Task SendMessage(string toNumber, string message) { var client = new TLSharp.Core.TelegramClient(apiId, apiHash); await client.ConnectAsync(); var dialogs = (TLDialogs)await client.GetUserDialogsAsync(); // this is because the contacts in the address come without the "+" prefix var normalizedNumber = toNumber.StartsWith("+") ? toNumber.Substring(1, toNumber.Length - 1) : toNumber; var user = dialogs.Users .OfType <TLUser>() .FirstOrDefault(x => x.Phone == normalizedNumber); await client.SendMessageAsync(new TLInputPeerUser() { UserId = user.Id, AccessHash = user.AccessHash.Value }, message); }