How to add contact from two different Telegram servers? - c#

Adding a contact from a country like Iran to a telegram account from Canada, causes an error says:
Unfortunately -name- has not joined telegram yet. But you can send
them an invitation.
I think that's because there are two different accounts from two different servers that aren't synced well.
Sometimes Iranian account can add Canadian account, and then Canadian can add Iranian as well, even if Iranian deletes Canadian from contacts. Or if a third person share their contacts or forward a message from one to another, they can add each other. I think these signs shows that telegram servers are not synced well.
As I'm using TLsharp to accomplish that, I can add two telegram accounts, one plays as that third person role, and shares Iranian contact to Canadian, and then he can save that contact.
My step by step plan is:
What I have is an Iranian Telegram account and Canadian one.
Iranian Customer opens my web site.
she/he fills telegram phone number field and submits.
we are going to start sending message in telegram by Canadian account.
try to add contact by Canadian account.
If failed, try to add contact by Iranian account. Else, we are done!
Share contact to Canadian Account.
Add contact by Canadian account.
My problem is:
how to have multiple telegram accounts in my code, because session file name is always "session.dat"
how to share contact in TLSharp
I can't forward message because there isn't any message yet. We should start messaging.
I also tried retrieving UserId and AccessHash by Iranian account, and using by Canadian account in this method:
await client.SendMessageAsync(new TLInputPeerUser() { UserId = xxx, AccessHash= yyyy}, "Hello");
but it has PEER_ID_INVALID error. (That is not true, I just took UserId from telegram!)

The problem is in number of contacts!
Telegram only supports about 1000 contacts (I found it experimental, there isn't any official source to prove this), and it will show you error when you want to add more contacts.
Trying to delete some contacts and reduce the count to 900, allowed me to add new contacts. So, the problem is not in telegram servers, it is in number of contacts limitation. Maybe they have a line of code like this:
Contact[] contacts = new Contact[1000]; //LOL
And for other two questions:
how to have multiple telegram accounts in my code, because session
file name is always "session.dat"
TLSharp.Core.TelegramClient clientAlt = new TLSharp.Core.TelegramClient(api_id, api_hash, sessionUserId: "sessionAlt");
There isn't any good documentation for TLSharp, but the problem solved by using sessionUserId as an optional parameter.
how to share contact in TLSharp?
TLInputMediaContact contact = new TLInputMediaContact()
{
FirstName = FirstName,
LastName = LastName,
PhoneNumber = PhoneNumber
};
TLRequestSendMedia req = new TLRequestSendMedia()
{
Media = contact,
Peer = new TLInputPeerUser() { UserId = AnotherTelegramAccountUserID.Id },
RandomId = UniqueNumber_ToPreventDuplicateMessages,
};
await clientAlt.SendRequestAsync<TLUpdates>(req);

Related

Concept of Token Program & Associated Token Account Program

I'm trying to send a token [USDT] from one wallet to another. But I think I'm having some trouble understanding the concept of Associated Token Account [ATA]
According to my understanding:
1 - Every wallet account that wants to keep, receive or send tokens, must register in the account for these tokens in the network?
2 - The sending person can register the account of the receiving person
3- Are these concepts correct?
All of the above are done by the following instructions =>
AssociatedTokenAccountProgram.CreateAssociatedTokenAccount
4 - Once the recipient's wallet address is registered, can send the tokens to him via instructions =>
TokenProgram.Transfer
Account ownerAccount = wallet.Account;
PublicKey UsdtAddress = new PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB");
PublicKey ToAddress = new PublicKey("CDQ3Gya9QermsPzU3cTNW9QPLbMVLbALQ2S8AwbruVJ");
var Transaction = new TransactionBuilder().
SetRecentBlockHash(blockHash.Result.Value.Blockhash).
SetFeePayer(wallet.Account).
AddInstruction(AssociatedTokenAccountProgram.CreateAssociatedTokenAccount(
ownerAccount, // Sender Account [Wallet Owner] ?
UsdtAddress, // Tether Address On-Chain ?
ToAddress)). // The Recipient Wallet Address ?
AddInstruction(TokenProgram.Transfer(
ownerAccount,
ToAddress,
100,
ownerAccount)).
Build(new List<Account> { ownerAccount });
var txReq = await rpcClient.SendTransactionAsync(Transaction);
I'm so sorry for the long wait, but after a lot of attempts, all of them were unsuccessful, I really think I need someone to explain how sending tokens works.
After a long struggle I was able to reach some results, I will leave this comment as a solution to the problem and an understanding of how things work, and if it contains some errors, please do not hesitate to leave an explanation and a correction for this
Let's agree on some concepts first:
1- Wallet account is a normal account, owned by the system Program and called [account owner]
2- The person who owns the private key is known as the authority
3 - Each token has an account on the chain, has its own owner and authority
what is happening now ?
If you want to own some of these tokens for the first time, you must create an account known as Associated Token Account
Associated Token Account: It is simply an account within the network that associates each wallet with a special and unique address of a token!! Is this clear??
Your wallet number => Associated Token Account <= token account number
G1G2G3G4 => A1T2A3T4 <= USDTADDRESS243
Its job is to save and store data for a specific wallet address with a specific token address, such as quantity, balance and many other features that I have not seen yet
The first time you will send these tokens to an account that does not contain [ATA], you will build instructions to create [ATA] for this account, and attach instructions directly to send the tokens with the same transaction, this structure worked for me,
Finally: It is possible to know the Associated Token Account for a wallet simply, because we will need to send the tokens with the Associated Tokens and not the addresses of the main wallets
Here is the code to create a Associated Token Account and send some USDT to the address:
PublicKey UsdtAddress = new PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB");
//The [ATA] for my public address in the USDT token account = Sender
Account ownerAccount = wallet.Account;
var FromAssociatedTokenAccount=AssociatedTokenAccountProgram.DeriveAssociatedTokenAccount(ownerAccount,UsdtAddress);
//The [ATA] for Receiver public address in the USDT token account = Sender = Receiver
PublicKey ToAddress = new PublicKey("DqiE6PDXPFMMDC2jzoqY45VEqyEzdGd5qauVCQY8s3A7");
var ToAssociatedTokenAccount = AssociatedTokenAccountProgram.DeriveAssociatedTokenAccount(ToAddress, UsdtAddress);
//Note that a ToAssociatedTokenAccount can be defined, with the possibility that it is not registered/created on-Chain
var blockHash = await rpcClient.GetRecentBlockHashAsync();
var Transaction = new TransactionBuilder().
SetRecentBlockHash(blockHash.Result.Value.Blockhash).
SetFeePayer(ownerAccount).
AddInstruction(AssociatedTokenAccountProgram.CreateAssociatedTokenAccount(
ownerAccount,
ToAddress,
UsdtAddress)).
AddInstruction(TokenProgram.Transfer(
FromAssociatedTokenAccount,
ToAssociatedTokenAccount,
1,
ownerAccount)).
Build(new List<Account> { ownerAccount });
var txReq = await rpcClient.SendTransactionAsync(Transaction);
So finally, please bring a cup of coffee and read this article, I think it is good to clarify some concepts about the Solana Blockchain :
https://www.brianfriel.xyz/how-to-create-a-token-on-solana/

Adding Bank Account in Stripe.NET for Managed Account

I've searched through the documentation on both the Stripe website and JaymeDavis' GitHub and still cannot manage to figure out if I'm correctly creating a bank account for a managed stripe account. From Stripe's website, it's clear this is what I need...
curl https://api.stripe.com/v1/accounts/acct_1032D82eZvKYlo2C/external_accounts \
-u sk_test_xxxxxxxxxxxxxxxxxxxxxx: \
-d external_account=btok_xxxxxxxxxxxxxxxxxxx
I have the token (btok....) returned from Stipe.js, and I have the account ID used in the curl link for the managed account, as well as the secret key. However, I cannot figure out what the process is to execute this in C#
My guess so far has been:
//Sample code for creating a managed account
StripeAccountService stripeAccountService = new StripeAccountService();
StripeAccountCreateOptions managedAccountCreateOption = new StripeAccountCreateOptions();
managedAccountCreateOption.Managed = true;
managedAccountCreateOption.Country = "US";
StripeRequestOptions connectAccountRequest = new StripeRequestOptions();
connectAccountRequest.ApiKey = ConfigurationManager.AppSettings["StripeApiKey"];
Stripe.StripeAccount response = stripeAccountService.Create(managedAccountCreateOption, connectAccountRequest);
// ADD Bank Account
var myAccount = new StripeAccountUpdateOptions();
myAccount.ExternalBankAccount.TokenId = "SampleToken";
var accountService = new StripeAccountService();
Stripe.StripeAccount bankAccount = accountService.Update(response.Id, myAccount);
The problem I'm having here is with adding the bank account. I want to create the bank account separately so that I can save the last 4 digits of a card/bank account (non-sensitive data) used in payouts in our database. The way above simply adds a single bank account to the managed user, and will not work as I would like to add multiple bank accounts for payouts. Any sample code in adding a bank account to an already existing managed account would help immensely (i.e. create a bank account with the token returned from Stripe.js, then in a separate action add this bank account to the managed user account so that I can grab the last 4 digits of this bank account as well as any additional accounts that are added in this way in the future). Thank you in advance for your help and time!
You can just retrieve a Managed Account instead of creating one, i.e.:
StripeAccount response = accountService.Get(accountId);
From there you can add additional Bank Accounts. The result of that API call is a BankAccount, and you should be able to access the last4 from there.

Batch Contact creation/update with contact photo

I am using EWS managed API to create and update contacts on the Exchange Server.
I am creating a contact like this (where user is an Active Directory Principal object with some custom properties):
Contact addContact = new Contact(service);
exchangeContact.NickName = GenerateNickName(user);
exchangeContact.DisplayName = exchangeContact.NickName;
exchangeContact.FileAs = user.DisplayName;
...
exchangeContact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = user.Phone;
exchangeContact.PhoneNumbers[PhoneNumberKey.MobilePhone] = user.MobilePhone;
ExtendedPropertyDefinition adGuidPropDef = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "ADGUID", MapiPropertyType.String);
exchangeContact.SetExtendedProperty(adGuidPropDef, user.Guid.ToString());
if (user.ThumbnailPhoto != null)
{
exchangeContact.SetContactPicture(user.ThumbnailPhoto);
}
exchangeContact.Save(parentFolderId);
This code part is called for around 500 * 500 contacts, and it is taking too long. I am looking to improve its performance. I tried to use the batch create/update methods but I found out they do not support "attachments", and that a contact photo is an attachment.
Is there another way to lower EWS calls or improve performance otherwise in this case?
There is nothing you can use to batch the Attachment creation but when you say 500 * 500 contacts are you creating 500 contact in 500 different mailboxes. That is to say you creating the same 500 contacts in each of those different mailboxes ?. If that's case the fastest way would be to create the contact once in a Master Mailbox and then copy the contact in to each of the Target Mailboxes. If you batch everything bar the Add Attachments that should give the best result.

Searching for certain mail addresses: The Method "Contains" is not supported

using Microsoft.Azure.ActiveDirectory.GraphClient, I want to get twenty accounts from Azure Active Directory; given their email addresses. I could now send twenty requests to the Azure AD server, but in the meantime, my script times out. So I tried a single request:
public override IEnumerable<IDirectoryEntry> GetEntriesForMails(IEnumerable<MailAddress> emails)
{
foreach(IUser user in _connection.Client.Users.Where(x => emails.Contains(x.Mail)).FlattenPages())
{
yield return new AzureDirectoryEntry(user, this);
}
This throws the error that
"Contains" is not supported.
Is there another, supported, way to get all user accounts for twenty email addresses in a single round trip to the server?
Try the code :
List<IUser> users = activeDirectoryClient.Users.ExecuteAsync().Result.CurrentPage.ToList();
List<IUser> user1 = users.Where(u => emails.Any(e => e.Contains(u.Mail))).ToList();
As per a Microsoft employee, there is no direct solution in the library.
The best solution we could come up with is to keep a client-side lookup table that maps email adresses to ObjectIds; and update that table regularly (daily/weekly, and whenever a lookup failed).
One can then get the Objects for 20 ObjectIds from Azure AD in a single call (GetObjectsByObjectIdsAsync method).

Retrieve all mobile devices Google Directory API in .NET Application

I want to Manage Device using Google API in my appilcation.How to retrieve all mobile/chrome OS device ?
CODE :
var listReq1 = service.Mobiledevices.List(serviceAccountEmail);
MobileDevices allUsers = listReq1.Execute();
Here,
serviceAccountEmail = "Service accounts Key" (Console.developer.google.com)
I am getting error like
Google.Apis.Requests.RequestError
Bad Request [400]
I tried using
var listReq= new Google.Apis.Admin.Directory.directory_v1.MobiledevicesResource.ListRequest(service,serviceAccountEmail);
Still not working ? I want all details of User just like Below Image
If you check the documentation for Mobiledevices: list
Retrieves a paginated list of all mobile devices for an account.
I will see that it takes a customer id as a parmater.
customerId The unique ID for the customer's Google account. As
an account administrator, you can also use the my_customer alias to
represent your account's customerId. The customerId is also returned
as part of the Users resource.
var listReq1 = service.Mobiledevices.List(customerId);
MobileDevices allUsers = listReq1.Execute();
You are sending service account email address which I really don't think is your customer id.

Categories