How to use Embedding with C#? Discord BOT - c#

I am looking to embed the following:
Using the Discord API. I have looked and the only resources I can find are for Python, Java, Ruby, etc.
But when using:
var embed = new Message.Embed(
{
Author =
{
Name = "Name",
Url = "www.url.com"
}
});
It comes back with the message:
And:
Not sure What I need to do to be able use the embed library. Just looking for some guidance on how this works
Edit:
When Using this I get no errors but when running the embed doesnt seem to build. It doesnt error. It just never builds the embed variable
var embed = new Message.Embed
{
Author =
{
Name = "Lawler",
Url = "www.twitch.tv/Lawler"
},
Title = "www.twitch.tv/Lawler",
Thumbnail =
{
ProxyUrl = "https://yt3.ggpht.com/-m-P7t2g-ecQ/AAAAAAAAAAI/AAAAAAAAAAA/YtS2YsD8-AM/s900-c-k-no-mo-rj-c0xffffff/photo.jpg",
Url = "www.twitch.tv/Lawler"
},
Description = "**Now Playing**\n" +
"Rocket League\n" +
"**Stream Title**\n" +
"Lawler RLCS Caster"
};
*Note: I am using Discord v 0.9.6

You can create an Embed Message like the following code (using the most recent version of Discord.Net):
var builder = new EmbedBuilder()
{
//Optional color
Color = Color.Green,
Description = "This is the description of the embed message"
};
Build a field inside the Embed Message:
builder.AddField(x =>
{
x.Name = Author.Name;
x.Value = Author.Url;
x.IsInline = false;
});
And reply to the same channel context:
//Use await if you're using an async Task to be completed.
await ReplyAsync("", false, builder.Build())
The code above should build an embed message, there are more options in the Discord.Net docs. Link: https://docs.stillu.cc/guides/introduction/intro.html
I hope you find this helpful.

Just a quick look at your code, I think you've got a close parenthesis in the wrong place.
Try the following:
var embed = new Message.Embed()
{
Author =
{
Name = "Name",
Url = "www.url.com"
}
};
Again, without doing any research you may also need to do the following:
var embed = new Message.Embed()
{
Author = new Author()
{
Name = "Name",
Url = "www.url.com"
}
};

var embed = new EmbedBuilder()
instead of
var embed = new Message.Embed()
To send the message:
await Context.Channel.SendMessageAsync("", false, embed);
EDIT: 0.9.6 doesn't support embeds, so the code above is useless

If you are in Discord.Net 1.0.1, you can format an embed like so:
var eb = new EmbedBuilder() { Title = "Cool Title", Description = "Description" };
Read the documentation here for more info here.
And if you want to make your text look a little better, you can read the Discord Markdown Documentation here. This works in 0.9.6.
To send an embed use:
await Context.Channel.SendMessageAsync("", false, eb);

Related

Not always a two way Related link in Azure DevOps using c#

I am creating a related link with the referenceName System.LinkTypes.Related in Azure DevOps programmatically using C# and Azure DevOps' SDK as below:
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Add(
new JsonPatchOperation
{
From = null,
Operation = Operation.Add,
Path = "/relations/-",
Value = new {
rel = "System.LinkTypes.Related",
url = $"https://dev.azure.com/{organization}/{projectName}/_workitems/edit/{relatedId}",
attributes = new
{
comment = $"Created programmatically on {DateTime.Now}."
}
}
}
);
await azureClient.UpdateWorkItemAsync(patchDoc, id, false, true, true, WorkItemExpand.All, cancellationToken: token);
The code above always created a two way link between id and relatedId.
But sometimes the link is one way!
How can i be sure to always create a link in both directions?

How to use SMS-Authentication in DocuSign

I'm trying to implement the SMS authentication with the aid of the DocuSign-SDK library.
var signer = new Signer {...};
signer.RequireIdLookup = "true";
signer.IdCheckConfigurationName = "SMS Auth $";
signer.SmsAuthentication = new RecipientSMSAuthentication {
SenderProvidedNumbers = new List<string> {
"0171*******"
}
};
When I try to send this envelope to the DocuSign API it will reply with the following error message:
Error calling CreateEnvelope:
{"errorCode":"INVALIDAUTHENTICATIONSETUP","message":"Recipient phone
number is invalid. Phone number for SMS Authentication: provided is
invalid. }
INVALIDAUTHENTICATIONSETUP: Authentication is not setup correctly for the recipient.
Is there something I have to enable on the DocuSign Admin page? I couldn't find any feature or something like that I need to enable.
Did I implement it the wrong way? Maybe someone can give me some suggestions.
Thanks
BTW: The given phone number should be valid.
EDIT:
When I'm using the new method as #Inbar wrote, I can't get the needed workflowId from the AccountsApi.
var client = new ApiClient(ApiClient.Demo_REST_BasePath);
var token = "eyJ1...";
client.Configuration.DefaultHeader.Add("Authorization", "Bearer " + token);
var accountsApi = new AccountsApi(client);
var response = accountsApi.GetAccountIdentityVerification(accountId);
var result = response.IdentityVerification; // Is empty. Why?
It seems that I have no IdentityVerification options which I can use for the authentication.
How can I enable such IdentityVerification options?
Or what else do I need to pay attention to?
Your code is using the older method, the new method code is provided in GitHub, I'll post it here too. You can find the article on Dev Center.
string workflowId = phoneAuthWorkflow.WorkflowId;
EnvelopeDefinition env = new EnvelopeDefinition()
{
EnvelopeIdStamping = "true",
EmailSubject = "Please Sign",
EmailBlurb = "Sample text for email body",
Status = "Sent"
};
byte[] buffer = System.IO.File.ReadAllBytes(docPdf);
// Add a document
Document doc1 = new Document()
{
DocumentId = "1",
FileExtension = "pdf",
Name = "Lorem",
DocumentBase64 = Convert.ToBase64String(buffer)
};
// Create your signature tab
env.Documents = new List<Document> { doc1 };
SignHere signHere1 = new SignHere
{
AnchorString = "/sn1/",
AnchorUnits = "pixels",
AnchorXOffset = "10",
AnchorYOffset = "20"
};
// Tabs are set per recipient/signer
Tabs signer1Tabs = new Tabs
{
SignHereTabs = new List<SignHere> { signHere1 }
};
string workflowId = workflowId;
RecipientIdentityVerification workflow = new RecipientIdentityVerification()
{
WorkflowId = workflowId,
InputOptions = new List<RecipientIdentityInputOption> {
new RecipientIdentityInputOption
{
Name = "phone_number_list",
ValueType = "PhoneNumberList",
PhoneNumberList = new List<RecipientIdentityPhoneNumber>
{
new RecipientIdentityPhoneNumber
{
Number = phoneNumber,
CountryCode = countryAreaCode,
}
}
}
}
};
Signer signer1 = new Signer()
{
Name = signerName,
Email = signerEmail,
RoutingOrder = "1",
Status = "Created",
DeliveryMethod = "Email",
RecipientId = "1", //represents your {RECIPIENT_ID},
Tabs = signer1Tabs,
IdentityVerification = workflow,
};
Recipients recipients = new Recipients();
recipients.Signers = new List<Signer> { signer1 };
env.Recipients = recipients;
I've created a new developer account on DocuSign and created a small test app in order to request identity verification options. Fortunately, that was working now and I got all available options but I do not understand why this is not working for my other developer account ("old").
When I compare both accounts I don't see the "Identity Verification" setting in the "old" account.
It is possible to activate this "Identity Verification" setting for my "old" dev account?
I guess that enabling this feature would solve the problem.
EDIT:
Ok, I've solved the problem.
I figured out that no IDV was configured for my developer account. In that case, the identity_verification call will return an empty array.
see: https://developers.docusign.com/docs/esign-rest-api/how-to/id-verification/
Also, I have read the following note in the DocuSign documentation:
Note: Phone authentication may not be enabled for some older developer
accounts. If you cannot choose to use phone authentication for your
account, contact support to request access. see:
https://developers.docusign.com/docs/esign-rest-api/esign101/concepts/recipients/auth/#id-verification-idv
So I contacted DocuSign support and they give me access to the IDV accordingly.
Now it is working fine.

C# Authentication error in google dialogflow API

How do i fix this. I want to set my authentication in my code and not on the machine.
I have checked almost every answer on stackoverflow and github, but none has a good explanation.
How do i pass the credentials to the create intent, it throws this error.
InvalidOperationException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
GoogleCredential credential =
GoogleCredential.FromFile(file);
//var credential = GoogleCredential.FromStream(
// Assembly.GetExecutingAssembly().GetManifestResourceStream("chatbot-a90a9-8f2fb910202d.json"))
// .CreateScoped(IntentsClient.DefaultScopes);
var storage = StorageClient.Create(credential);
var client = IntentsClient.Create();
var text = new Intent.Types.Message.Types.Text();
text.Text_.Add("Message Text");
var message = new Intent.Types.Message()
{
Text = text
};
var trainingPhrasesParts = new List<string>
{
"Book a fligt",
"check cheap flights"
};
var phraseParts = new List<Intent.Types.TrainingPhrase.Types.Part>();
foreach (var part in trainingPhrasesParts)
{
phraseParts.Add(new Intent.Types.TrainingPhrase.Types.Part()
{
Text = part
});
}
var trainingPhrase = new Intent.Types.TrainingPhrase();
trainingPhrase.Parts.AddRange(phraseParts);
var intent = new Intent();
intent.DisplayName = "test";
intent.Messages.Add(message);
intent.TrainingPhrases.Add(trainingPhrase);
var newIntent = client.CreateIntent(
parent: new AgentName("chatbot-a90a9"),
intent: intent
);
SOLVED.
I change
var client = IntentsClient.Create();
To
IntentsClientBuilder builder = new IntentsClientBuilder
{
CredentialsPath = file, // Relative to where the code is executing or absolute path.
// Scopes = IntentsClient.DefaultScopes // Commented out because there's no need to specify this since you are using the defaults and all default values will be automatically used for values not specified in the builder.
};
IntentsClient client = builder.Build();

How do i add Link to firebase cloud messaging with .net admin sdk

I am using the Firebase .net Admin SDK on my back end to send push notifications.
According to this link I should be able to add the following json into a message object that will open the set link when the notification is clicked on while the app is in background.
"webpush": {
"fcm_options": {
"link": "https://dummypage.com"
}
I have read through the .net Admin Sdk documentation but cannot figure out where to add this.
Here is the code that I used to new up the message object
var fcm = FirebaseAdmin.Messaging.FirebaseMessaging.DefaultInstance;
var Message = new Message()
{
Notification = new Notification
{
Title = title,
Body = message,
},
Token = user.PushTokenWeb,
};
var result = await fcm.SendAsync(Message);
Does anyone know where I would set the callback link?
In FirebaseAdmin .net v1.9.0 you can
var message = new Message()
{
Token = token,
Notification = new Notification()
{
Body = notificationBody,
Title = title
},
Android = new AndroidConfig()
{
Priority = Priority.High
},
Webpush = new WebpushConfig()
{
FcmOptions = new WebpushFcmOptions()
{
Link= "https://www.davnec.eu/aurora-boreale/previsioni/"
}
}
};
.NET SDK does not support this setting yet. It's only exposed in Node.js and Go at the moment. You can provide a pull request at https://github.com/firebase/firebase-admin-dotnet to implement this feature.

How to publish a post with multiple attachments to a user's facebook profile?

My facebook app uses the Facebook C# SDK to publish to a user's Facebook profile. I'm currently publishing multiple posts with one attachment, but I'd much rather publish one summary post with multiple attachments. I've done this with the JavaScript API, but is it possible with the C# SDK?
This is my current publish code:
FacebookApp app = new FacebookApp(user.AccessToken);
string userFeedPath = String.Format("/{0}/feed/", user.FacebookUserId);
string message = String.Format("{0} earned an achievement in {1}",
user.SteamUserId, achievement.Game.Name);
dynamic parameters = new ExpandoObject();
parameters.link = achievement.Game.StatsUrl;
parameters.message = message;
parameters.name = achievement.Name;
parameters.description = achievement.Description;
parameters.picture = achievement.ImageUrl;
app.Api(userFeedPath, parameters, HttpMethod.Post);
We currently don't support multiple attachments. As far as I know you can't publish multiple attachments with either the graph or rest api. If you have a sample that shows how to do it, I will get it implemented in the SDK.
i have the same code as yours but it doesent work for me. I am trying this:
public void plesni()
{
try
{
dynamic parameters = new ExpandoObject();
parameters.message = "xxxxxxx";
parameters.link = "xxxxxxxx";
// parameters.picture=""
parameters.name = "xxxxxx";
parameters.caption = "xxxxxxx";
parameters.description = "xxxxxxxxxx";
parameters.actions = new
{
name = "xxxxxxx",
link = "http://www.xxxxxxxxxxxxxx.com",
};
parameters.privacy = new
{
value = "ALL_FRIENDS",
};
parameters.targeting = new
{
countries = "US",
regions = "6,53",
locales = "6",
};
dynamic result = app.Api("/uid/feed/", parameters, HttpMethod.Post);
// app.Api("/uid/feed", parameters);
Response.Write("Sucess");
}
catch (FacebookOAuthException)
{
Response.Write("...... <br/>");
}
}
if instead of uid I put me it works fine.
I am hoping for your help.
Have a good day.

Categories

Resources