Install-Package Microsoft.AspNet.WebApi.HelpPage
Adding Help Documentation to a Web API REST Service
http://localhost:54212/Help
REST POST Build a REST Service in Visual Studio 2015 Part 1
Install-Package Microsoft.AspNet.WebApi.HelpPage
Adding Help Documentation to a Web API REST Service
http://localhost:54212/Help
REST POST Build a REST Service in Visual Studio 2015 Part 1
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using System.Net.Http;
using System.Threading;
using System.Diagnostics;
using System.Security.Cryptography;
namespace APITest
{
public class Config
{
private static readonly Lazy<Config> lazy =
new Lazy<Config>(() => new Config(), LazyThreadSafetyMode.ExecutionAndPublication);
public static Config Instance { get { return lazy.Value; } }
public string apiKey
{
get { return "apiGwKey"; }
}
public string accessKey
{
get { return "accessKey"; }
}
public string secureKey
{
get { return "secureKey"; }
}
public string ncpUrl
{
get { return @"https://ncloud.apigw.ntruss.com/clouddb/v1/"; }
}
}
class Program
{
static void Main(string[] args)
{
Config config = Config.Instance;
var postParams = new List<KeyValuePair<string, string>>();
postParams.Add(new KeyValuePair<string, string>("dbKindCode", "MSSQL"));
postParams.Add(new KeyValuePair<string, string>("responseFormatType", "json"));
AsyncCall asyncCall = new AsyncCall();
Task<string> t = asyncCall.NCloudApiCall("getCloudDBConfigGroupList", postParams, config.apiKey, config.accessKey, config.secureKey, config.ncpUrl);
t.Wait();
Console.WriteLine(t.Result);
}
}
class AsyncCall
{
public async Task<string> NCloudApiCall(string action, List<KeyValuePair<string, string>> postParams, string apiKey, string accessKey, string secureKey, string ncpUrl)
{
string responseString = string.Empty;
try
{
HttpClient client = Client.Instance.getClient();
string timestamp = string.Empty;
string sig = Auth.Instance.makePostSignature(action, ref timestamp, apiKey, accessKey, secureKey);
string url = ncpUrl + action;
var content = new FormUrlEncodedContent(postParams);
client.DefaultRequestHeaders.Add("x-ncp-apigw-timestamp", timestamp);
client.DefaultRequestHeaders.Add("x-ncp-apigw-api-key", apiKey);
client.DefaultRequestHeaders.Add("x-ncp-iam-access-key", accessKey);
client.DefaultRequestHeaders.Add("x-ncp-apigw-signature-v1", sig);
var response = await client.PostAsync(url, content);
responseString = await response.Content.ReadAsStringAsync();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return responseString;
}
}
class Auth
{
private static readonly Lazy<Auth> lazy =
new Lazy<Auth>(() => new Auth(), LazyThreadSafetyMode.ExecutionAndPublication);
public static Auth Instance { get { return lazy.Value; } }
public string makePostSignature(string action, ref string stringtimestamp, string apiKey, string accessKey, string secureKey)
{
if (string.IsNullOrEmpty(action))
return "parameter error";
long timestamp = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
string space = " ";
string newLine = "\n";
string method = "POST";
string url = @"/clouddb/v1/" + action;
stringtimestamp = timestamp.ToString();
string message = new StringBuilder()
.Append(method)
.Append(space)
.Append(url)
.Append(newLine)
.Append(stringtimestamp)
.Append(newLine)
.Append(apiKey)
.Append(newLine)
.Append(accessKey)
.ToString();
Debug.WriteLine(message);
byte[] secretKey = Encoding.UTF8.GetBytes(secureKey);
HMACSHA256 hmac = new HMACSHA256(secretKey);
hmac.Initialize();
byte[] bytes = Encoding.UTF8.GetBytes(message);
byte[] rawHmac = hmac.ComputeHash(bytes);
Debug.WriteLine(Convert.ToBase64String(rawHmac));
return Convert.ToBase64String(rawHmac);
}
}
class Client
{
private static readonly Lazy<Client> lazy =
new Lazy<Client>(() => new Client(), LazyThreadSafetyMode.ExecutionAndPublication);
public static Client Instance { get { return lazy.Value; } }
private readonly HttpClient client = new HttpClient();
public HttpClient getClient()
{
return client;
}
}
}
[bot 만들기]
텔레그램 안에서 BotFather 친구 맺음
/start
/newbot
yourbotname
yourbotname_bot
Use this token to access the HTTP API:
0000000:VVVhJhOKsTl_2Vppzc93OKsOd0PpLVcVZlM
For a description of the Bot API, see this page: https://core.telegram.org/bots/api
/token
@yourbotname_bot
[그룹만들어 봇 초대하기]
인간 사용자가 그룹을 만들어
봇 사용자가 그룹을 찾아 들어감 Add to Group
[봇이 들어간 group 내 사용자 리스트 구하기]
https://api.telegram.org/bot00000000:fdsafdsafda_dsafdsafdas/getUpdates
id 양수는 개인
id 음수는 그룹
-- 이제 코딩
https://github.com/TelegramBots/Telegram.Bot.Examples/blob/master/Telegram.Bot.Examples.Echo/Program.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.InlineQueryResults;
using Telegram.Bot.Types.ReplyMarkups;
namespace telegramtest2
{
class Program
{
private static readonly TelegramBotClient Bot = new Telegram.Bot.TelegramBotClient("botid");
//private static readonly TelegramBotClient Bot = new Telegram.Bot.TelegramBotClient("botid");
static void Main(string[] args)
{
Bot.OnMessage += Bot_OnMessage;
var me = Bot.GetMeAsync().Result;
Console.Title = me.Username;
//SendMsg(5646546464565, "메롱2");
/// Recv Start
Bot.StartReceiving();
Console.ReadLine();
/// Recv Stop
Bot.StopReceiving();
Console.ReadKey();
}
private static async void SendMsg(long chatId, string message)
{
await Bot.SendTextMessageAsync(chatId, message);
}
private static async void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs messageEventArgs)
{
var message = messageEventArgs.Message;
if (message.Text.StartsWith("/cmd"))
{
Console.WriteLine(message.Chat.Id);
Debug.WriteLine(message.Chat.Id);
await Bot.SendTextMessageAsync(message.Chat.Id, "나한테 일시키기 마라");
}
}
}
}