您需要返回一个带有键“text”和“type”的JSON响应,如示例所示
here
{
"type": "message",
"text": "This is a reply!"
}
如果您正在使用NodeJS,您可以尝试
this sample code
Content
和
ContentType
使其工作(如图所示
here
). 这是一个简单的机器人程序的代码,它可以回应用户在频道中键入的内容,请根据您的场景随意调整。
使用azure函数的自定义MS团队机器人示例代码
#r "Newtonsoft.Json"
using System.Net;
using System.Net.Http.Headers;
using Newtonsoft.Json;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
log.Info(JsonConvert.SerializeObject(data));
// Set name to query string or body data
name = name ?? data?.text;
Response res = new Response();
res.type = "Message";
res.text = $"You said:{name}";
var response = req.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(JsonConvert.SerializeObject(res));
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
return response;
}
public class Response {
public string type;
public string text;
}