Skip to content

how to send a message

찰스 edited this page Jul 31, 2023 · 3 revisions

simple text message send

using (var client = new LineMessagingClient("your channelacesstoken"))
{
    await client.Message.SendPushMessageAsync("user id", new TextMessage("hello world"));
}

send text message with X-Line-Retry-Key header

using (var client = new LineMessagingClient("your channelacesstoken"))
{
    await client.Message.SendPushMessageAsync(
        "user id", 
        new TextMessage("hello world"), 
        xLineRetryKey: Guid.NewGuid().ToString());
}

how to get a value of response header

offer LineDevelopers v1.1.10 or higher

using (var client = new LineMessagingClient("your channelaccesstoken"))
{
    await client.Message.SendPushMessageAsync(
        "user id", 
        new TextMessage("hello world"),
        xLineRetryKey: Guid.NewGuid().ToString(), 
        getResponseHeaders: (o) =>
        {
            IEnumerable<string> xLineRequestId;
            IEnumerable<string> xLineAcceptedRequestId;

            if (o.TryGetValues("X-Line-Request-Id", out xLineRequestId))
            {
                Console.WriteLine(xLineRequestId.First());
            }

            if (o.TryGetValues("X-Line-Accepted-Request-Id", out xLineAcceptedRequestId))
            {
                Console.WriteLine(xLineAcceptedRequestId.First());
            }
        });
}