How can I send message to telegram using API and C#? [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have channel and I want to send automatic messages to this channel using C# and telegram API.
What should I do?

First create a bot and add that as an administrator to your channel
help:
Adding Bot as administrator to channel
Creating Bot
then use the following code to send message to your group
WebRequest req = WebRequest.Create("https://api.telegram.org/bot" + yourToken + "/sendMessage?chat_id=" + channel_id + "&text=" + message);
req.UseDefaultCredentials = true;
var result = req.GetResponse();
req.Abort();
yourToken is your bot's token, channel_id is your channel's ID and message is a string that you want to send to your channel

Related

How to receive HTML response from WEB API in C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
How to receive and print below error in C#.(See below screeshot)
This error is coming while posting the data to customer WEB API.
Code block used for Posting data to customer API.
var response = client.PostAsync(URL, content).Result;
Console.WriteLine("Status Code:" + (int)response.StatusCode); //output = 404
Console.WriteLine("Reason:" + response.ReasonPhrase); //output = Not Found
Please suggest?
try this
var body = await response.Content.ReadAsStringAsync();

How to send messages with Firebase admin SDK [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Nuget used:
FireBaseAdmin v1.9.2
I'm trying to use firebase admin to send push notification to fcm.
I read the documentation but can't find any other good source to figure out how to use it properly.
I can't figure out where to add the serverkey and senderid.
I made a methode for sending push notifications.
Has anyone an example i could follow or any other documentation?
public override async Task<string> Send(List<String> tokens, string title, string body)
{
var message = Message()
{
Tokens = tokens,
Notification = new Notification()
{
Title = title,
Body = body
}
};
return await FirebaseMessaging.DefaultInstance.SendAsync(message).ConfigureAwait(false);
}
When i debug this code the response is null from SendAsync.
It might be because i didn't give it the serverkey and senderId but then i would expect an error like serverKeyNotFound.
Server key and sender ID parameters are not used in the Admin SDK. You just need to instantiate a FirebaseApp with some GoogleCredential as shown in https://firebase.google.com/docs/admin/setup.
On top of that your code seems to be syntactically incorrect. There's no Tokens property available in the Message class. You need MulticastMessage class for that. So I'd expect the above code to fail compilation.

How can I change an email string to hide the identity with C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
my C# code is returning this from WebAPI
return Ok(new
{
email = user.Email,
sent = true
});
I want to make it so that the full email is not sent.
Can anyone suggest a good way that I could make it send:
The first 2 characters of the address
...
The last two before the # to the end of the address
So for example
davesmith#live.com
is returned as
da...th#live.com
Bit of a problem are emails with less then 4 character before #. You Could start with
private static string ShortenMail(string mail)
{
var regex = new Regex("^(.{1,2}).*?(.{0,2}#.*)$");
return regex.Replace(mail, "$1...$2");
}
And call it via ShortenMail("davesmith#live.com");
I changed it a bit, so shorter mails are possible.
You can do something like this maybe:
string email = "davesmith#live.com";
string maskedEmail = string.Format("{0}...{1}", email.Substring(0, 2), email.Substring(email.LastIndexOf("#") - 2));

I have a desktop application and I want to send a POST to a webpage and then show that webpage [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a desktop application that has some classes, which I want to serialize and send to a webpage when a user clicks a button in the desktop C# application.
The data is too long for an argument. What I want to achieve here is, how do I post it and open the website on the clients PC with the dynamic changes made by the sent data ?
Need some suggestions or guidance to proceed in the right direction.
You can use HttpClient
For example:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://myUrl");
var gizmo = new Product() { Name = "Gizmo", Price = 100, Category = "Widget" };
response = await client.PostAsJsonAsync("api/products", gizmo);
if (response.IsSuccessStatusCode)
{
//do something
}
}
One option would be to generate local page with form that contains data and "action=POST" pointing to your site. Than set script that automatically submit this form and as result you'll have data send by browser and browser will continue as if it is normal POST request.
If you don't like HttpClient you can also use WebClient which is a convenience wrapper for your exact scenario.

How to call a URL in C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Currently working with Unity, this might a super basic question, but here goes.
I need to call a URL from my app in C#. This is done for analytics purposes, and so I don't want to open a web browser or anything, just call the URL and that's it. I know about Application.OpenURL() to open the browser, but how do I achieve this without opening the browser ?
You may try like this:
var client = new WebClient();
var x = client.DownloadString("http://example.com");
or
HttpWebRequest request = WebRequest.Create("http://example.com") as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream stream = response.GetResponseStream();
Use the WebClient class in the System.Net namespace.
It's a high level implementation of an HTTP client which is really easy to use.
Has a method called .DownloadString() which does exactly what you want - calls a URL using HTTP GET and returns the response as a string.

Categories