Hello everybody, I pretty new to programming, what I want to do is a C# program that will send a message to a Microsoft teams group via a webhook connector of this group. I was able to achieve it with a Desktop code(with form),but I need it to be a console program, I have pretty much copy/paste the code from my Desktop project to my console project, but there something that don't work. Here is my code from my desktop project:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace test_team_2
{
public partial class Form1 : Form
{
string[] cmdLineMe = Environment.GetCommandLineArgs();
string webhookPdfTermine = "uri to my team groups;
HttpClient client = new HttpClient();
Message body = new Message();
string finalMessage = "";
public Form1()
{
InitializeComponent();
}
private void Form1\_Load(object sender, EventArgs e)
{
for (int i = 0; i < cmdLineMe.Length; i++)
{
finalMessage = cmdLineMe\[i\];
}
sendMsg();
}
public class Message
{
public string text { get; set; }
}
private async Task SendMsgAsync()
{
MessageBox.Show(finalMessage);
client.BaseAddress = new Uri(webhookPdfTermine);
body.text = finalMessage;
string serializeJson = JsonSerializer.Serialize(body);
StringContent content = new StringContent(serializeJson, Encoding.UTF8, "application/json");
\_ = await client.PostAsync(client.BaseAddress, content);
}
void sendMsg()
{
\_ = SendMsgAsync();
}
}
}
And here is my code for my console project:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
namespace TeamBots
{
class Program
{
string[] cmdLineMe = Environment.GetCommandLineArgs();
string webhookPdfTermine = "uri to my team groups";
HttpClient client = n