I'm successfully using the Twilio API in an ASP.net C# app using the sample code (obviously changing the variables as required):
static void Main(string[] args)
{
// Find your Account Sid and Auth Token at twilio.com/console
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const string authToken = "your_auth_token";
TwilioClient.Init(accountSid, authToken);
var to = new PhoneNumber("+15017122661");
var message = MessageResource.Create(
to,
from: new PhoneNumber("+15558675310"),
body: "This is the ship that made the Kessel Run in fourteen parsecs?");
Console.WriteLine(message.Sid);
}
I'm sure I read somewhere that you can change what the message receiver sees on their phone - so you could have 'my company' instead of the phone number the message is sent from.
However, I can't find this anywhere in Google or on the Twilio API C# samples.
How can I do this?
Thanks.
This article is more clear on the requirements. It is a paid account feature only:
Alphanumeric Sender ID is automatically supported on all new upgraded (paid) Twilio accounts. It is not supported for Free Trial accounts.
and
This feature is only available for upgraded (paid) Twilio accounts sending messages to supported countries. Some supported countries may have additional requirements, including pre-registration for alpha sender IDs, or limiting these messages to be only sent as transactional messages.
There are also instructions there for checking if it supported on your account. I believe short code is a different concept, using a 5 or 6 digit number for the sender id, which is also associated with larger message rate limits and of course paid account only as well.
Related
I have been using the "Shared Envelopes" feature to allow specific users who are not the sender or a recipient of the envelope to be able to view an envelope in my application without any issues. I used the following instructions to do so:
How to embed the DocuSign UI in your app:
https://developers.docusign.com/docs/esign-rest-api/how-to/embed-ui/
This lays out using the SDK method Envelopes::createConsoleView.
However, DocuSign has deprecated "Shared Envelopes" in favor of their new "Shared Access".
I removed the users from the "Shared Envelopes" of the sending account and added them to "Shared Access" of the sending account. Unfortunately, when I make this change the users can no longer view the envelope and receive the following error message:
Error calling CreateConsoleView: {"errorCode":"USER_NOT_ENVELOPE_SENDER_OR_RECIPIENT","message":"This user is not the sender or a recipient of the envelope. Only the sender or a recipient of the envelope may perform the requested operation."}
Here is my code:
//API - EnvelopeViews:createConsoleView
public string GetEnvelopeViewUrl(string accountId, string envelopeId, string returnUrl)
{
var token = _tokenService.FetchToken(accountId);
var apiClient = new DocuSignClient($"{token.Account.BaseUri}/restapi");
apiClient.Configuration.DefaultHeader.Add("Authorization", $"Bearer {token.Value}");
var envelopesApi = new EnvelopesApi(apiClient);
var apiAccountId = _config["DocuSign:ApiAccountId"];
ConsoleViewRequest viewRequest = new ConsoleViewRequest
{
EnvelopeId = envelopeId,
ReturnUrl = returnUrl
};
var recipientView = envelopesApi.CreateConsoleView(apiAccountId, viewRequest);
return recipientView.Url;
}
I know the users in my app are not the sender or a recipient of the envelope. I thought that was the whole point of "Shared Access". Can anyone provide some guidance on how to enable the new "Shared Access" users to be able to view an envelope like they can with the old "Shared Envelopes" in my application?
Baxter, as of right now (November 2022) the new feature for Shared Access is only to support using the web app and does not provide any functionality for developers using the API.
The old feature, like you mentioned, called shared envelopes, was fully supporting the API and the call you made would work with that.
There's a future plan to support the API using Shared Access, but I don't know the details or the date. I can update this answer once I have this information.
First, I'm a total noob with AWS Lambda so I wanted to see if anyone can point me in the right direction to setting up an AWS Lambda function that will send a Twilio MMS message that would be triggered by an upload of an image to an S3 bucket? I guess C# isn't a hard set requirement but it would be nice since that is the language that I'm currently working with.
I'm currently doing this via my app but want to offload this to an AWS Lambda function if at all possible.
TIA
I'm neither a C# expert nor very familiar with AWS Lamda, but this post here should get you started.
And this documentation page explains how to send messages with C#. So the only thing you need to do is add the Twilio Account SID and Auth key to the Lamda environment variables, and there you go.
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
class Program
{
static void Main(string[] args)
{
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
TwilioClient.Init(accountSid, authToken);
var message = MessageResource.Create(
body: "Join Earth's mightiest heroes. Like Kevin Bacon.",
from: new Twilio.Types.PhoneNumber("+15017122661"),
to: new Twilio.Types.PhoneNumber("+15558675310")
);
Console.WriteLine(message.Sid);
}
}
I am trying to use the Microsoft Bot Framework DirectLine API to read and add messages to existing conversations between other users and my bot. From what I've read I believe this should be possible when using the master-secret but it's just not working for me. I'm using a WebAPI to try and access two of my existing conversations (on Facebook & Skype) as follows:
[HttpPost]
[Route("remind")]
public string Remind()
{
var secret = System.Configuration.ConfigurationManager.AppSettings["secret"];
var uri = new Uri("https://directline.botframework.com/");
var creds = new DirectLineClientCredentials(secret);
DirectLineClient client = new DirectLineClient(uri, creds);
Conversations convs = new Conversations(client);
var conversationIDs = new string[] { "0000000000000000-0000000000000000", "00:0123456789abcdefghijklmnopqrstuvwxyz0123456789-A-_0123456798ABCDEF" }; // Existing Facebook & Skype conversations
// Send a message to each conversation:
foreach (var conversationID in conversationIDs)
{
Message message = new Message(conversationId: conversationID, fromProperty: "My Bot", text: "Hey dude, remember that thing!");
Console.WriteLine(message.Text);
convs.PostMessage(conversationID, message); // FAILS - This executes but doesn't do anything.
}
// Try reading the messages from a conversation (just to test if it's working):
string waterMark = null;
var set = convs.GetMessages(conversationIDs[0], waterMark); // FAILS - This fails with a 404 not found.
waterMark = set.Watermark;
return "Done :-)";
}
It fails silently calling PostMessage() and fails with a 404 for the GetMessages(). I seem to be doing the right thing, the bot is live etc and works very well in Facebook & Skype separately from the DirectLine API. It only works if I create a new conversation using the DirectLine API, I can then access its messages and post new messages to it.
This question sort of helps but doesn't quite tell me what to do to fix it:
Difficulty accessing messages in an existing conversation in Microsoft Bot Framework
Any help would be much appreciated.
Thanks
For security reasons, you can't use DirectLine to spy on messages from another conversation. For the scenario you describe (escalating to a human) there a number of different ways to approach this. One is to have your bot broker conversations between the accounts (i.e. Facebook End User <-> Your Bot <-> Facebook Support Person). Each is talking to the bot, and the bot passes the message through to the other user. (Could also be Facebook User <-> Your Bot <-> Skype User) Your bot would have to store last n messages to provide context. Alternatively, I've seen folks build their own customer support chat interface using direct line that sits on the far side. Hope this helps
When I attempt to send an image file using the Twilio.SendMessage Rest API call, I get the error : Code 21612 - The 'To' phone number is not currently reachable via SMS or MMS.
Here is the code I use:
var message = twilio.SendMessage(fromPhone, phone, "a message for you", new string[] {"http://website.com/images/folder/pic.jpg"});
This phone number works fine for text messages. I checked with my carrier, and my plan includes "picture Messaging" as well. So I am questioning the validity of the error message. Is there something else I need to check or do to get this to work?
This happened to me when I used Alphanumeric sender id (ex: TWILLIO) when sending messages. So USA doesn't support alphanumeric sender ids. You can see the list of countries support or need to be pre-registered to support alphanumeric sender id. The list
Error code explanation
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?
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;