using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
public class CustomScript : ScriptBase
{
public override async Task<HttpResponseMessage> ExecuteAsync()
{
try
{
// Read the request body
var requestBody = await this.Context.Request.Content.ReadAsStringAsync();
// Parse the JSON content
var json = JObject.Parse(requestBody);
var name = json["Name"].ToString();
// Create the greeting message
var greeting = $"Hello, {name}";
// Create the response
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent($"{{ \"Greeting\": \"{greeting}\" }}", Encoding.UTF8, "application/json")
};
return response;
}
catch (Exception ex)
{
// Log the exception and return an error response
var errorResponse = new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
Content = new StringContent($"{{ \"error\": \"{ex.Message}\" }}", Encoding.UTF8, "application/json")
};
return errorResponse;
}
}
}
Thank you for any help!