채널 관련 기능 구현

적용 대상: SDK v4

일부 채널은 메시지 텍스트 및 첨부 파일로만 구현할 수 없는 기능을 제공합니다. 채널 관련 기능을 구현하려면 활동 개체의 채널 데이터 속성에서 채널에 네이티브 메타데이터를 전달할 수 있습니다. 예를 들어, 봇은 채널 데이터 속성을 사용하여 Telegram에 스티커를 전송하도록 지시하거나 Office365에 이메일을 전송하도록 지시할 수 있습니다.

이 문서에서는 메시지 작업의 채널 데이터 속성을 사용하여 다음과 같은 채널 관련 기능을 구현하는 방법을 설명합니다.

채널 기능
Email 본문, 제목 및 중요도 메타데이터가 포함된 전자 메일을 보내고 받습니다.
Facebook 기본적으로 Facebook 알림을 보냅니다.
LINE LINE 관련 메시지 유형을 구현하는 메시지를 보냅니다.
Slack 전체 충실도 Slack 메시지를 보냅니다.
Teams Microsoft Teams 메시지에서 @-멘션을 처리합니다.
Telegram 음성 메모 또는 스티커 공유와 같은 전보 관련 작업을 수행합니다.

참고

활동 개체의 채널 데이터 속성 값은 JSON 개체입니다. 따라서 이 문서의 예제에서는 다양한 시나리오에서 예상되는 channelData JSON 속성의 형식을 보여줍니다. .NET을 사용하여 JSON 개체를 만들려면 JObject(.NET) 클래스를 사용합니다.

사용자 지정 전자 메일 메시지 만들기

사용자 지정 전자 메일 메시지를 만들려면 활동 channelData 속성을 다음 속성을 포함하는 JSON 개체로 설정합니다.

속성 Description
bccRecipients 메시지의 Bcc(숨은 참조) 필드에 추가할 세미콜론(;)으로 구분된 이메일 주소 문자열입니다.
ccRecipients 메시지의 Cc(참조) 필드에 추가할 세미콜론(;)으로 구분된 이메일 주소 문자열입니다.
htmlBody 이메일 메시지의 본문을 지정하는 HTML 문서입니다. 지원되는 HTML 요소 및 특성에 대한 정보는 채널의 설명서를 참조하세요.
importance 이메일의 중요도 수준입니다. 유효한 값은 높음, 기본낮음입니다. 기본값은 기본입니다.
toRecipients 메시지의 받는 사람 필드에 추가할 세미콜론(;)으로 구분된 이메일 주소 문자열입니다.

사용자와 봇 간의 나가는 메시지와 들어오는 메시지에는 이전 표에 속성이 지정된 JSON 개체가 포함된 활동이 있을 수 있습니다 channelData . 아래 코드 조각은 봇에서 사용자로 들어오는 사용자 지정 전자 메일 메시지에 대한 속성의 channelData 예제를 보여줍니다.

{
    "type": "ActivityTypes.Message",
    "locale": "en-Us",
    "channelID": "email",
    "fromName": { "id": "mybot@mydomain.com", "name": "My bot"},
    "recipientName": { "id": "joe@otherdomain.com", "name": "Joe Doe"},
    "conversation": { "id": "123123123123", "topic": "awesome chat" },
    "channelData":
    {
        "htmlBody": "<html><body style = \"font-family: Calibri; font-size: 11pt;\" >This is more than awesome.</body></html>",
        "importance": "high",
        "ccRecipients": "Yasemin@adatum.com;Temel@adventure-works.com",
    }
}

Facebook 알림 만들기

Facebook 알림을 만들려면 활동 개체의 채널 데이터 속성을 이러한 속성을 지정하는 JSON 개체로 설정합니다.

속성 Description
notification_type 알림 유형(예: REGULAR, SILENT_PUSH 또는 NO_PUSH)입니다.
attachment 이미지, 비디오 또는 다른 멀티미디어 형식을 지정하는 첨부 파일 또는 영수증과 같은 템플릿 기반 첨부 파일입니다.

참고

notification_type 속성 및 attachment 속성의 형식 및 콘텐츠에 대한 자세한 내용은 Facebook API 설명서를 참조하세요.

이 코드 조각은 Facebook 영수증 첨부 파일에 대한 channelData 속성의 예제를 보여 줍니다.

"channelData": {
    "notification_type": "NO_PUSH",
    "attachment": {
        "type": "template"
        "payload": {
            "template_type": "receipt",
            //...
        }
    }
}

LINE 메시지 만들기

LINE 관련 메시지 유형(예: 스티커, 템플릿 또는 휴대폰 카메라 열기와 같은 LINE 관련 작업 유형)을 구현하는 메시지를 만들려면 활동 개체의 채널 데이터 속성을 LINE 메시지 유형 및 작업 유형을 지정하는 JSON 개체로 설정합니다.

속성 Description
type LINE 작업/메시지 유형 이름

다음과 같은 LINE 메시지 유형이 지원됩니다.

  • 스티커
  • 이미지맵
  • 템플릿(단추, 확인, 회전식)
  • Flex

이러한 LINE 작업은 메시지 유형 JSON 개체의 작업 필드에 지정할 수 있습니다.

  • 포스트백
  • 메시지
  • URI
  • Datetimerpicker
  • Camera
  • 카메라 앨범
  • 위치

이러한 LINE 메서드 및 해당 매개 변수에 대한 자세한 내용은 LINE Bot API 설명서를 참조하세요.

이 코드 조각은 채널 메시지 유형을 ButtonTemplate 지정하는 속성의 channelData 예제와 "camera", "cameraRoll" 및 "datetimepicker"의 세 가지 작업 유형을 보여 줍니다.

"channelData": {
    "type": "template",
    "altText": "This is a buttons template",
    "template": {
        "type": "buttons",
        "thumbnailImageUrl": "https://example.com/bot/images/image.jpg",
        "imageAspectRatio": "rectangle",
        "imageSize": "cover",
        "imageBackgroundColor": "#FFFFFF",
        "title": "Menu",
        "text": "Please select",
        "defaultAction": {
            "type": "uri",
            "label": "View detail",
            "uri": "http://example.com/page/123"
        },
        "actions": [{
                "type": "cameraRoll",
                "label": "Camera roll"
            },
            {
                "type": "camera",
                "label": "Camera"
            },
            {
                "type": "datetimepicker",
                "label": "Select date",
                "data": "storeId=12345",
                "mode": "datetime",
                "initial": "2017-12-25t00:00",
                "max": "2018-01-24t23:59",
                "min": "2017-12-25t00:00"
            }
        ]
    }
}

완전히 신뢰할 수 있는 Slack 메시지 만들기

전체 충실도 Slack 메시지를 만들려면 활동 개체의 채널 데이터 속성을 다음을 지정하는 JSON 개체로 설정합니다.

참고

설정 단추에서 Slack 메시지를 지원 해야 합니다 대화형 메시지 때 있습니다 봇을 연결 Slack 채널에 있습니다.

이 코드 조각은 사용자 지정 Slack 메시지에 대한 channelData 속성의 예제를 보여 줍니다.

"channelData": {
   "text": "Now back in stock! :tada:",
   "attachments": [
        {
            "title": "The Further Adventures of Slackbot",
            "author_name": "Stanford S. Strickland",
            "author_icon": "https://api.slack.com/img/api/homepage_custom_integrations-2x.png",
            "image_url": "http://i.imgur.com/OJkaVOI.jpg?1"
        },
        {
            "fields": [
                {
                    "title": "Volume",
                    "value": "1",
                    "short": true
                },
                {
                    "title": "Issue",
                    "value": "3",
                    "short": true
                }
            ]
        },
        {
            "title": "Synopsis",
            "text": "After @episod pushed exciting changes to a devious new branch back in Issue 1, Slackbot notifies @don about an unexpected deploy..."
        },
        {
            "fallback": "Would you recommend it to customers?",
            "title": "Would you recommend it to customers?",
            "callback_id": "comic_1234_xyz",
            "color": "#3AA3E3",
            "attachment_type": "default",
            "actions": [
                {
                    "name": "recommend",
                    "text": "Recommend",
                    "type": "button",
                    "value": "recommend"
                },
                {
                    "name": "no",
                    "text": "No",
                    "type": "button",
                    "value": "bad"
                }
            ]
        }
    ]
}

사용자가 Slack 메시지 내의 단추를 클릭하면 봇은 채널 데이터 속성이 payload JSON 개체로 채워진 응답 메시지를 받게 됩니다. payload 개체는 원본 메시지의 콘텐츠를 지정하고, 클릭된 단추를 식별하고, 단추를 클릭한 사용자를 식별합니다.

이 코드 조각은 사용자가 Slack 메시지에서 단추를 클릭할 때 봇에서 수신하는 메시지에서 channelData 속성의 예제를 보여줍니다.

"channelData": {
    "payload": {
        "actions": [
            {
                "name": "recommend",
                "value": "yes"
            }
        ],
        //...
        "original_message": "{...}",
        "response_url": "https://hooks.slack.com/actions/..."
    }
}

봇은 일반적인 방식으로 이 메시지에 응답하거나 payload 개체의 response_url 속성으로 지정된 엔드포인트에 해당 응답을 직접 게시할 수 있습니다. response_url에 응답을 게시하는 시기 및 방법에 대한 정보는 Slack 단추를 참조하세요.

다음 JSON을 사용하여 동적 단추를 만들 수 있습니다.

{
    "text": "Would you like to play a game ? ",
    "attachments": [
        {
            "text": "Choose a game to play!",
            "fallback": "You are unable to choose a game",
            "callback_id": "wopr_game",
            "color": "#3AA3E3",
            "attachment_type": "default",
            "actions": [
                {
                    "name": "game",
                    "text": "Chess",
                    "type": "button",
                    "value": "chess"
                },
                {
                    "name": "game",
                    "text": "Falken's Maze",
                    "type": "button",
                    "value": "maze"
                },
                {
                    "name": "game",
                    "text": "Thermonuclear War",
                    "style": "danger",
                    "type": "button",
                    "value": "war",
                    "confirm": {
                        "title": "Are you sure?",
                        "text": "Wouldn't you prefer a good game of chess?",
                        "ok_text": "Yes",
                        "dismiss_text": "No"
                    }
                }
            ]
        }
    ]
}

대화형 메뉴를 만들려면 다음 JSON을 사용합니다.

{
    "text": "Would you like to play a game ? ",
    "response_type": "in_channel",
    "attachments": [
        {
            "text": "Choose a game to play",
            "fallback": "If you could read this message, you'd be choosing something fun to do right now.",
            "color": "#3AA3E3",
            "attachment_type": "default",
            "callback_id": "game_selection",
            "actions": [
                {
                    "name": "games_list",
                    "text": "Pick a game...",
                    "type": "select",
                    "options": [
                        {
                            "text": "Hearts",
                            "value": "menu_id_hearts"
                        },
                        {
                            "text": "Bridge",
                            "value": "menu_id_bridge"
                        },
                        {
                            "text": "Checkers",
                            "value": "menu_id_checkers"
                        },
                        {
                            "text": "Chess",
                            "value": "menu_id_chess"
                        },
                        {
                            "text": "Poker",
                            "value": "menu_id_poker"
                        },
                        {
                            "text": "Falken's Maze",
                            "value": "menu_id_maze"
                        },
                        {
                            "text": "Global Thermonuclear War",
                            "value": "menu_id_war"
                        }
                    ]
                }
            ]
        }
    ]
}

Teams에 봇 추가

팀에 추가된 봇은 대화의 일부로 @mentioned일 수 있는 다른 팀 멤버가 됩니다. 실제로 봇은 인 경우에만 메시지를 수신하므로 채널의 @mentioned다른 대화는 봇으로 전송되지 않습니다. 자세한 내용은 Microsoft Teams Bot을 사용하는 채널 및 그룹 채팅 대화를 참조하세요.

그룹 또는 채널의 봇은 메시지에 언급된 경우에만 응답하므로(@botname) 그룹 채널의 봇에서 받은 모든 메시지에는 고유한 이름이 포함되며 메시지 구문 분석에서 이를 처리해야 합니다. 또한 봇은 언급된 다른 사용자를 구문 분석하여 해당 사용자를 메시지의 일부로 언급할 수 있습니다.

@bot 멘션 확인 및 제거

Mention[] m = sourceMessage.GetMentions();
var messageText = sourceMessage.Text;

for (int i = 0;i < m.Length;i++)
{
    if (m[i].Mentioned.Id == sourceMessage.Recipient.Id)
    {
        //Bot is in the @mention list.
        //The below example will strip the bot name out of the message, so you can parse it as if it wasn't included. Note that the Text object will contain the full bot name, if applicable.
        if (m[i].Text != null)
            messageText = messageText.Replace(m[i].Text, "");
    }
}
var text = message.text;
if (message.entities) {
    message.entities
        .filter(entity => ((entity.type === "mention") && (entity.mentioned.id.toLowerCase() === botId)))
        .forEach(entity => {
            text = text.replace(entity.text, "");
        });
    text = text.trim();
}

중요

테스트 이외의 용도로 GUID로 봇을 추가하는 것은 권장되지 않습니다. 이렇게 하면 봇의 기능이 심각하게 제한됩니다. 프로덕션 환경의 봇은 앱의 일부로 Teams에 추가해야 합니다. 봇 만들기Microsoft Teams 봇 테스트 및 디버그를 참조하세요.

Telegram 메시지 만들기

음성 메모 또는 스티커 공유와 같은 Telegram 관련 작업을 구현하는 메시지를 만들려면 활동 개체의 채널 데이터 속성을 이러한 속성을 지정하는 JSON 개체로 설정합니다.

속성 Description
method 호출할 Telegram Bot API 메서드입니다.
매개 변수 지정된 메서드의 매개 변수입니다.

다음과 같은 Telegram 메서드가 지원됩니다.

  • answerInlineQuery
  • editMessageCaption
  • editMessageReplyMarkup
  • editMessageText
  • forwardMessage
  • banChatMember
  • sendAudio
  • sendChatAction
  • sendContact
  • sendDocument
  • sendLocation
  • sendMessage
  • sendPhoto
  • sendSticker
  • sendVenue
  • sendVideo
  • sendVoice
  • unbanChatMember

이러한 Telegram 메서드 및 해당 매개 변수에 대한 자세한 내용은 Telegram Bot API 설명서를 참조하세요.

참고

  • chat_id 매개 변수는 모든 Telegram 메서드에 공통적입니다. 매개 변수로 지정 chat_id 하지 않으면 프레임워크에서 ID를 제공합니다.
  • 파일 콘텐츠 인라인을 전달하는 대신 아래 예제에서와 같이 URL 및 미디어 형식을 사용하여 파일을 지정합니다.
  • 봇이 Telegram 채널에서 받는 각 메시지 내에서 ChannelData 속성은 봇이 이전에 전송한 메시지를 포함합니다.

이 코드 조각은 단일 Telegram 메서드를 channelData 지정하는 속성의 예를 보여줍니다.

"channelData": {
    "method": "sendSticker",
    "parameters": {
        "sticker": {
            "url": "https://domain.com/path/gif",
            "mediaType": "image/gif",
        }
    }
}

이 코드 조각은 Telegram 메서드의 배열을 channelData 지정하는 속성의 예를 보여 줍니다.

"channelData": [
    {
        "method": "sendSticker",
        "parameters": {
            "sticker": {
                "url": "https://domain.com/path/gif",
                "mediaType": "image/gif",
            }
        }
    },
    {
        "method": "sendMessage",
        "parameters": {
            "text": "<b>This message is HTML formatted.</b>",
            "parse_mode": "HTML"
        }
    }
]

Telegram 메서드가 구현되면 채널 데이터 속성이 JSON 개체로 채워진 응답 메시지가 봇에 표시됩니다. 이 응답 개체는 update_id 및 최대 하나의 선택적 매개 변수를 포함하여 원본 메시지의 내용을 지정합니다. 들어오는 응답을 받는 방법에 대한 자세한 내용은 업데이트 가져오기를 참조하세요.

이 코드 조각은 설문 조사를 만들 때 봇이 받는 메시지의 channelData 속성 예제를 보여 줍니다.

"channelData": {
    "update_id": 43517575,
    "message": {
        "message_id": 618,
        "from": {
            "id": 803613355,
            "is_bot": false,
            "first_name": "Joe",
            "last_name": "Doe",
            "username": "jdoe",
            "language_code": "en"
        },
        "chat": {
            "id": 803613355,
            "first_name": "Joe",
            "last_name": "Doe",
            "username": "jdoe",
            "type": "private"
        },
        "date": 1582577834,
        "poll": {
        "id": "5089525250643722242",
        "question": "How to win?",
        "options": [
            {
                "text": "Be the best",
                "voter_count": 0
            },
            {
                "text": "Help those in need",
                "voter_count": 0
            },
            {
                "text": "All of the above",
                "voter_count": 0
            }
        ],
        "total_voter_count": 0,
        "is_closed": false,
        "is_anonymous": true,
        "type": "regular",
        "allows_multiple_answers": false
        }
    }
}

추가 리소스