Initial commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LineMessaging
|
||||
{
|
||||
public partial class LineMessagingClient
|
||||
{
|
||||
private const string GroupMemberApiPath = "/v2/bot/group/{0}/member/{1}";
|
||||
private const string GroupMembersApiPath = "/v2/bot/group/{0}/members/ids";
|
||||
private const string LeaveGroupApiPath = "/v2/bot/group/{0}/leave";
|
||||
|
||||
public async Task<LineProfile> GetGroupMember(string groupId, string userId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(groupId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(groupId)} is null or empty.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(userId)} is null or empty.");
|
||||
}
|
||||
|
||||
return await Get<LineProfile>(string.Format(GroupMemberApiPath, groupId, userId));
|
||||
}
|
||||
|
||||
public async Task<LineMembers> GetGroupMembers(string groupId, string start = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(groupId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(groupId)} is null or empty.");
|
||||
}
|
||||
|
||||
var query = new Dictionary<string, object>();
|
||||
if (start != null)
|
||||
{
|
||||
query["start"] = start;
|
||||
}
|
||||
|
||||
return await Get<LineMembers>(string.Format(GroupMembersApiPath, groupId), query);
|
||||
}
|
||||
|
||||
public async Task LeaveGroup(string groupId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(groupId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(groupId)} is null or empty.");
|
||||
}
|
||||
|
||||
await Post(string.Format(LeaveGroupApiPath, groupId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LineMessaging
|
||||
{
|
||||
public partial class LineMessagingClient
|
||||
{
|
||||
private const string MessageContentApiPath = "/v2/bot/message/{0}/content";
|
||||
|
||||
public Task<byte[]> GetMessageContent(string messageId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(messageId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(messageId)} is null or empty.");
|
||||
}
|
||||
|
||||
return GetAsByteArray(string.Format(MessageContentApiPath, messageId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LineMessaging
|
||||
{
|
||||
public partial class LineMessagingClient
|
||||
{
|
||||
private const string LineMessagePushApiPath = "/v2/bot/message/push";
|
||||
private const string LineMessageMulticastApiPath = "/v2/bot/message/multicast";
|
||||
|
||||
public async Task PushMessage(LinePushMessage pushMessage)
|
||||
{
|
||||
if (pushMessage == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(pushMessage));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(pushMessage.To))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(pushMessage.To)} is null or empty.");
|
||||
}
|
||||
|
||||
var messageCount = pushMessage.Messages.Count();
|
||||
if (pushMessage.Messages == null || messageCount == 0 || messageCount > 5)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(pushMessage.Messages)} is required and max length is 5.");
|
||||
}
|
||||
|
||||
await Post(LineMessagePushApiPath, pushMessage);
|
||||
}
|
||||
|
||||
public async Task PushMessage(string to, ILineMessage message)
|
||||
{
|
||||
if (to == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(to));
|
||||
}
|
||||
|
||||
if (message == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
|
||||
await Post(LineMessagePushApiPath, new LinePushMessage
|
||||
{
|
||||
To = to,
|
||||
Messages = new List<ILineMessage> { message }
|
||||
});
|
||||
}
|
||||
|
||||
public async Task PushMessage(string to, IEnumerable<ILineMessage> messages)
|
||||
{
|
||||
if (to == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(to));
|
||||
}
|
||||
|
||||
if (messages == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(messages));
|
||||
}
|
||||
|
||||
var messageCount = messages.Count();
|
||||
if (messageCount == 0 || messageCount > 5)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(messages)} is required and max length is 5.");
|
||||
}
|
||||
|
||||
await Post(LineMessagePushApiPath, new LinePushMessage
|
||||
{
|
||||
To = to,
|
||||
Messages = messages
|
||||
});
|
||||
}
|
||||
|
||||
public async Task PushMessage(string to, string message)
|
||||
{
|
||||
if (to == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(to));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(message))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(message)} is null or empty.");
|
||||
}
|
||||
|
||||
await Post(LineMessagePushApiPath, new LinePushMessage
|
||||
{
|
||||
To = to,
|
||||
Messages = new List<ILineMessage> { new LineTextMessage { Text = message } }
|
||||
});
|
||||
}
|
||||
|
||||
public async Task PushMessage(string to, params string[] messages)
|
||||
{
|
||||
if (to == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(to));
|
||||
}
|
||||
|
||||
if (messages == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(messages));
|
||||
}
|
||||
|
||||
if (messages.Length == 0 || messages.Length > 5)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(messages)} is required and max length is 5.");
|
||||
}
|
||||
|
||||
await Post(LineMessagePushApiPath, new LinePushMessage
|
||||
{
|
||||
To = to,
|
||||
Messages = messages.Select(x => (ILineMessage)new LineTextMessage { Text = x }).ToList()
|
||||
});
|
||||
}
|
||||
|
||||
public async Task MulticastMessage(LineMulticastMessage multicastMessage)
|
||||
{
|
||||
if (multicastMessage == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(multicastMessage));
|
||||
}
|
||||
|
||||
var toCount = multicastMessage.To.Count();
|
||||
if (multicastMessage.To == null || toCount == 0 || toCount > 150)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(multicastMessage.To)} is required and max length is 150.");
|
||||
}
|
||||
|
||||
var messageCount = multicastMessage.Messages.Count();
|
||||
if (multicastMessage.Messages == null || messageCount == 0 || messageCount > 5)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(multicastMessage.Messages)} is required and max length is 5.");
|
||||
}
|
||||
|
||||
await Post(LineMessageMulticastApiPath, multicastMessage);
|
||||
}
|
||||
|
||||
public async Task MulticastMessage(IEnumerable<string> to, ILineMessage message)
|
||||
{
|
||||
if (to == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(to));
|
||||
}
|
||||
|
||||
if (message == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
|
||||
var toCount = to.Count();
|
||||
if (toCount == 0 || toCount > 150)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(to)} is required and max length is 150.");
|
||||
}
|
||||
|
||||
await Post(LineMessageMulticastApiPath, new LineMulticastMessage
|
||||
{
|
||||
To = to,
|
||||
Messages = new List<ILineMessage> { message }
|
||||
});
|
||||
}
|
||||
|
||||
public async Task MulticastMessage(IEnumerable<string> to, IEnumerable<ILineMessage> messages)
|
||||
{
|
||||
if (to == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(to));
|
||||
}
|
||||
|
||||
if (messages == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(messages));
|
||||
}
|
||||
|
||||
var toCount = to.Count();
|
||||
if (toCount == 0 || toCount > 150)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(to)} is required and max length is 150.");
|
||||
}
|
||||
|
||||
var messageCount = messages.Count();
|
||||
if (messageCount == 0 || messageCount > 5)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(messages)} is required and max length is 5.");
|
||||
}
|
||||
|
||||
await Post(LineMessageMulticastApiPath, new LineMulticastMessage
|
||||
{
|
||||
To = to,
|
||||
Messages = messages
|
||||
});
|
||||
}
|
||||
|
||||
public async Task MulticastMessage(IEnumerable<string> to, string message)
|
||||
{
|
||||
if (to == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(to));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(message))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(message)} is null or empty.");
|
||||
}
|
||||
|
||||
var toCount = to.Count();
|
||||
if (toCount == 0 || toCount > 150)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(to)} is required and max length is 150.");
|
||||
}
|
||||
|
||||
await Post(LineMessageMulticastApiPath, new LineMulticastMessage
|
||||
{
|
||||
To = to,
|
||||
Messages = new List<ILineMessage> { new LineTextMessage { Text = message } }
|
||||
});
|
||||
}
|
||||
|
||||
public async Task MulticastMessage(IEnumerable<string> to, params string[] messages)
|
||||
{
|
||||
if (to == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(to));
|
||||
}
|
||||
|
||||
if (messages == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(messages));
|
||||
}
|
||||
|
||||
var toCount = to.Count();
|
||||
if (toCount == 0 || toCount > 150)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(to)} is required and max length is 150.");
|
||||
}
|
||||
|
||||
var messageCount = messages.Count();
|
||||
if (messageCount == 0 || messageCount > 5)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(messages)} is required and max length is 5.");
|
||||
}
|
||||
|
||||
await Post(LineMessageMulticastApiPath, new LineMulticastMessage
|
||||
{
|
||||
To = to,
|
||||
Messages = messages.Select(x => (ILineMessage)new LineTextMessage { Text = x }).ToList()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LineMessaging
|
||||
{
|
||||
public partial class LineMessagingClient
|
||||
{
|
||||
private const string MessageReplyApiPath = "/v2/bot/message/reply";
|
||||
|
||||
public async Task ReplyMessage(LineReplyMessage replyMessage)
|
||||
{
|
||||
if (replyMessage == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(replyMessage));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(replyMessage.ReplyToken))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(replyMessage.ReplyToken)} is null or empty.");
|
||||
}
|
||||
|
||||
var messageCount = replyMessage.Messages.Count();
|
||||
if (replyMessage.Messages == null || messageCount == 0 || messageCount > 5)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(replyMessage.Messages)} is required and max length is 5.");
|
||||
}
|
||||
|
||||
await Post(MessageReplyApiPath, replyMessage);
|
||||
}
|
||||
|
||||
public async Task ReplyMessage(string replyToken, IEnumerable<ILineMessage> messages)
|
||||
{
|
||||
if (string.IsNullOrEmpty(replyToken))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(replyToken)} is null or empty.");
|
||||
}
|
||||
|
||||
if (messages == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(messages));
|
||||
}
|
||||
|
||||
var messageCount = messages.Count();
|
||||
if (messageCount == 0 || messageCount > 5)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(messages)} is required and max length is 5.");
|
||||
}
|
||||
|
||||
await Post(MessageReplyApiPath, new LineReplyMessage
|
||||
{
|
||||
ReplyToken = replyToken,
|
||||
Messages = messages
|
||||
});
|
||||
}
|
||||
|
||||
public async Task ReplyMessage(string replyToken, string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(replyToken))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(replyToken)} is null or empty.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(message))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(message)} is null or empty.");
|
||||
}
|
||||
|
||||
await Post(MessageReplyApiPath, new LineReplyMessage
|
||||
{
|
||||
ReplyToken = replyToken,
|
||||
Messages = new List<ILineMessage> { new LineTextMessage { Text = message } }
|
||||
});
|
||||
}
|
||||
|
||||
public async Task ReplyMessage(string replyToken, params string[] messages)
|
||||
{
|
||||
if (string.IsNullOrEmpty(replyToken))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(replyToken)} is null or empty.");
|
||||
}
|
||||
|
||||
if (messages == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(messages));
|
||||
}
|
||||
|
||||
if (messages.Length == 0 || messages.Length > 5)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(messages)} is required and max length is 5.");
|
||||
}
|
||||
|
||||
await Post(MessageReplyApiPath, new LineReplyMessage
|
||||
{
|
||||
ReplyToken = replyToken,
|
||||
Messages = messages.Select(x => (ILineMessage)new LineTextMessage { Text = x }).ToList()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LineMessaging
|
||||
{
|
||||
public partial class LineMessagingClient
|
||||
{
|
||||
private const string ProfileApiPath = "/v2/bot/profile/{0}";
|
||||
|
||||
public async Task<LineProfile> GetProfile(string userId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(userId)} is null or empty.");
|
||||
}
|
||||
|
||||
return await Get<LineProfile>(string.Format(ProfileApiPath, userId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LineMessaging
|
||||
{
|
||||
public partial class LineMessagingClient
|
||||
{
|
||||
private const string RichMenuApiPath = "/v2/bot/richmenu/{0}";
|
||||
private const string RichMenusApiPath = "/v2/bot/richmenu";
|
||||
private const string UsersRichMenuApiPath = "/v2/bot/user/{0}/richmenu";
|
||||
private const string LinkUsersRichMenuApiPath = "/v2/bot/user/{0}/richmenu/{1}";
|
||||
private const string RichMenuContentApiPath = "/v2/bot/richmenu/{0}/content";
|
||||
|
||||
public async Task<LineRichMenuResponse> GetRichMenu(string richMenuId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(richMenuId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(richMenuId)} is null or empty.");
|
||||
}
|
||||
|
||||
return await Get<LineRichMenuResponse>(string.Format(RichMenuApiPath, richMenuId));
|
||||
}
|
||||
|
||||
public async Task<string> CreateRichMenu(LineRichMenu richMenu)
|
||||
{
|
||||
if (richMenu == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(richMenu));
|
||||
}
|
||||
|
||||
var response = await Post<RichMenuIdResponse>(RichMenusApiPath, richMenu);
|
||||
return response?.RichMenuId;
|
||||
}
|
||||
|
||||
public async Task DeleteRichMenu(string richMenuId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(richMenuId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(richMenuId)} is null or empty.");
|
||||
}
|
||||
|
||||
await Delete(string.Format(RichMenuApiPath, richMenuId));
|
||||
}
|
||||
|
||||
public async Task<string> GetUsersRichMenuId(string userId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(userId)} is null or empty.");
|
||||
}
|
||||
|
||||
var response = await Get<RichMenuIdResponse>(string.Format(UsersRichMenuApiPath, userId));
|
||||
return response?.RichMenuId;
|
||||
}
|
||||
|
||||
public async Task LinkUsersRichMenu(string userId, string richMenuId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(userId)} is null or empty.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(richMenuId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(richMenuId)} is null or empty.");
|
||||
}
|
||||
|
||||
await Post(string.Format(LinkUsersRichMenuApiPath, userId, richMenuId));
|
||||
}
|
||||
|
||||
public async Task UnlinkUsersRichMenu(string userId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(userId)} is null or empty.");
|
||||
}
|
||||
|
||||
await Delete(string.Format(UsersRichMenuApiPath, userId));
|
||||
}
|
||||
|
||||
public async Task<byte[]> GetRichMenuContent(string richMenuId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(richMenuId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(richMenuId)} is null or empty.");
|
||||
}
|
||||
|
||||
return await GetAsByteArray(string.Format(RichMenuContentApiPath, richMenuId));
|
||||
}
|
||||
|
||||
internal class RichMenuIdResponse
|
||||
{
|
||||
[JsonProperty("richMenuId")]
|
||||
internal string RichMenuId { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LineMessaging
|
||||
{
|
||||
public partial class LineMessagingClient
|
||||
{
|
||||
private const string RoomMemberApiPath = "/v2/bot/room/{0}/member/{1}";
|
||||
private const string RoomMembersApiPath = "/v2/bot/room/{0}/members/ids";
|
||||
private const string LeaveRoomApiPath = "/v2/bot/room/{0}/leave";
|
||||
|
||||
public async Task<LineProfile> GetRoomMember(string roomId, string userId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(roomId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(roomId)} is null or empty.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(userId)} is null or empty.");
|
||||
}
|
||||
|
||||
return await Get<LineProfile>(string.Format(RoomMemberApiPath, roomId, userId));
|
||||
}
|
||||
|
||||
public async Task<LineMembers> GetRoomMembers(string roomId, string start = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(roomId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(roomId)} is null or empty.");
|
||||
}
|
||||
|
||||
var query = new Dictionary<string, object>();
|
||||
if (start != null)
|
||||
{
|
||||
query["start"] = start;
|
||||
}
|
||||
|
||||
return await Get<LineMembers>(string.Format(RoomMembersApiPath, roomId), query);
|
||||
}
|
||||
|
||||
public async Task LeaveRoom(string roomId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(roomId))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(roomId)} is null or empty.");
|
||||
}
|
||||
|
||||
await Post(string.Format(LeaveRoomApiPath, roomId));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user