/// <summary>
        /// グループメンバーのプロフィールを取得する
        /// </summary>
        /// <param name="channelAccessToken">ChannelAccessToken</param>
        /// <param name="groupId">グループID</param>
        /// <param name="userId">ユーザID</param>
        /// <returns></returns>
        public static async Task <GetUserProfileInGroupOrRoomMemberResponse> GetUserProfileInGroupMember(
            string channelAccessToken,
            string groupId,
            string userId
            )
        {
            Trace.TraceInformation("Start");

            // 引数のnullチェック
            if (channelAccessToken == null)
            {
                Trace.TraceWarning("Channel Access Token is Null");
                return(null);
            }
            if (groupId == null)
            {
                Trace.TraceWarning("Group Id is Null");
                return(null);
            }
            if (userId == null)
            {
                Trace.TraceWarning("User Id is Null");
                return(null);
            }

            string requestUrl =
                ConfigurationManager.AppSettings["BaseUrl"] +
                ConfigurationManager.AppSettings["GroupUrl"] +
                groupId +
                ConfigurationManager.AppSettings["GroupProfileUrl"] +
                userId;
            GetUserProfileInGroupOrRoomMemberResponse response = await MessagingApiSender.SendMessagingApi <string, GetUserProfileInGroupOrRoomMemberResponse>(
                channelAccessToken,
                requestUrl
                ).ConfigureAwait(false);

            Trace.TraceInformation("End");

            return(response);
        }
示例#2
0
        /// <summary>
        /// テキストメッセージイベント実行
        /// </summary>
        /// <param name="text">テキスト本文</param>
        private async Task ExecuteTextMessageEvent(
            string channelAccessToken,
            SourceBase source,
            string replyToken,
            string text
            )
        {
            Trace.TraceInformation("Start");

            // 引数nullチェック
            if (channelAccessToken == null)
            {
                Trace.TraceInformation("Channel Access Token is Null");
                return;
            }
            if (source == null)
            {
                Trace.TraceWarning("Source is Null");
                return;
            }
            if (text == null)
            {
                Trace.TraceWarning("Text is Null");
                return;
            }

            switch (text)
            {
            case "プロフィールほしい":

                if (source is GroupSource)
                {
                    string groupId = (source as GroupSource).groupId;
                    if (groupId == null)
                    {
                        Trace.TraceInformation("Group Id is Null");
                        return;
                    }
                    string userId = (source as GroupSource).userId;
                    if (userId == null)
                    {
                        Trace.TraceInformation("User Id is Null");
                        return;
                    }

                    GetUserProfileInGroupOrRoomMemberResponse profilesResponse =
                        await GroupService.GetUserProfileInGroupMember(channelAccessToken, groupId, userId)
                        .ConfigureAwait(false);

                    string messageText =
                        "表示名:" + profilesResponse.displayName +
                        "ID:" + profilesResponse.userId +
                        "画像:" + profilesResponse.pictureUrl +
                        "\n";

                    await ReplyMessageService.SendReplyMessage(
                        channelAccessToken,
                        replyToken,
                        MessageFactoryService.CreateMessage()
                        .AddTextMessage(messageText)
                        ).ConfigureAwait(false);
                }

                else if (source is RoomSource)
                {
                    string roomId = (source as RoomSource).roomId;
                    if (roomId == null)
                    {
                        Trace.TraceInformation("Room Id is Null");
                        return;
                    }
                    string userId = (source as RoomSource).userId;
                    if (userId == null)
                    {
                        Trace.TraceInformation("User Id is Null");
                        return;
                    }

                    GetUserProfileInGroupOrRoomMemberResponse profilesResponse =
                        await RoomService.GetUserProfileInRoomMember(channelAccessToken, roomId, userId)
                        .ConfigureAwait(false);

                    string messageText =
                        "表示名:" + profilesResponse.displayName +
                        "ID:" + profilesResponse.userId +
                        "画像:" + profilesResponse.pictureUrl +
                        "\n";

                    await ReplyMessageService.SendReplyMessage(
                        channelAccessToken,
                        replyToken,
                        MessageFactoryService.CreateMessage()
                        .AddTextMessage(messageText)
                        ).ConfigureAwait(false);
                }

                else if (source is UserSource)
                {
                    string userId = (source as UserSource).userId;
                    if (userId == null)
                    {
                        Trace.TraceInformation("User Id is Null");
                        return;
                    }

                    await ReplyMessageService.SendReplyMessage(
                        channelAccessToken,
                        replyToken,
                        MessageFactoryService.CreateMessage()
                        .AddTextMessage("リプライ")
                        ).ConfigureAwait(false);

                    GetProfileResponse profile = await ProfileService.GetProfile(channelAccessToken, userId).ConfigureAwait(false);

                    Trace.TraceInformation("User Id is " + profile?.userId);
                    Trace.TraceInformation("Display Name is " + profile?.displayName);
                    Trace.TraceInformation("Status Message is " + profile?.statusMessage);
                    Trace.TraceInformation("Picture Url is " + profile?.pictureUrl);
                }

                break;

            case "茜ちゃん帰って":

                if (source is GroupSource)
                {
                    string groupId = (source as GroupSource).groupId;
                    if (groupId == null)
                    {
                        Trace.TraceInformation("Group Id is Null");
                        return;
                    }

                    await GroupService.LeaveGroup(channelAccessToken, groupId).ConfigureAwait(false);
                }

                else if (source is RoomSource)
                {
                    string roomId = (source as RoomSource).roomId;
                    if (roomId == null)
                    {
                        Trace.TraceInformation("Room Id is Null");
                        return;
                    }

                    await RoomService.LeaveRoom(channelAccessToken, roomId).ConfigureAwait(false);
                }

                break;



            default:
                Trace.TraceInformation("Unexpected Text");
                break;
            }

            Trace.TraceInformation("End");
            return;
        }