Search code examples
c#smstwilioaccounts

User Master Account to send SMS on behalf of a Sub Account


I'm developing a feature for our product that will allow users to send SMS messages via Twilio and we handle all of the account issues. We have our Master Account and all of our customers will be sub accounts under us.

In an effort to not have to keep track of 1000+ auth tokens, we decided to use our Master Account credentials to send the SMS message however we still want it to roll up under the sub account. According to Twilio, this shouldn't be an issue.

My problem is that there is very little (that I've found) documentation for the c# library they provide. I'm not sure if what I've done is the correct way to accomplish what I described above and since I'm on a trial account until the project is finished and can be rolled out to production I have no way of testing.

        var twilio = new TwilioRestClient("Master SID", "Master Auth Token");
        var response = twilio.SendSmsMessage(sender, recipient.ConvertToE164Format(), message, null, "Subaccount SID");

The comment on this overload isn't really clear on if passing the subaccounts SID here will send the message as if I had logged into their account and sent it.

    //   applicationSid:
    //     Twilio will POST SmsSid as well as SmsStatus=sent or SmsStatus=failed to
    //     the URL in the SmsStatusCallback property of this Application. If the StatusCallback
    //     parameter above is also passed, the Application's SmsStatusCallback parameter
    //     will take precedence.

The callback url will be the same across all accounts so I don't need/care about that value.

Short Version: If I log in with my Master Account details but pass the subaccount SID in the SendSmsMessage() method, which account does the message come from?


Solution

  • Twilio support finally got back to me and confirmed my fears that this wouldn't work. I do have to pull the subaccount information down and reinstantiate the twilioRestClient with the new credentials which I was hoping I could get away with not doing. Just a few extra lines.

            var twilio = new TwilioRestClient("Master SID", "Master Auth Token");
            var subAccount = twilio.GetAccount("SubAccount SID");
            var subAccountClient = new TwilioRestClient(subAccount.Sid, subAccount.AuthToken);
            var response = subAccountClient.SendSmsMessage(sender, recipient.ConvertToE164Format(), message);
    
            return response.Sid;