Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 1 year has passed since last update.

[2023.11 Hands-On] 4 WOFF アプリ表示のフロー

Last updated at Posted at 2023-08-05

Power Automate で WOFF を作成

Power Automate にサインイン

割り当てられた Microsoft アカウントで Microsoft Power Automate にアクセスします。
user@lwugdev.onmicrosoft.com -> このドメイン名のアカウントです。

URL: https://make.powerautomate.com/

フロー作成

Power Automate のクラウド フローを作成します。
[+ 作成] をクリックしてフローの作成を開始します。
image.png

[自動化したクラウド フロー] のタイルを選択し、
image.png

起動したウィザードで [スキップ] をクリックします。
image.png

スクリーンショットの編集画面だった場合は、[...] から [クラシックデザイナーに切り替える]を実行します。
image.png

トリガー作成

フローのトリガーとして [HTTP 要求の受信時] を用います。
一覧から探すか、または検索して "要求" を選択してください。

image.png

トリガーで "HTTP 要求の受信時" を選択。
image.png

[Who can trigger the flow?] で [anyone] を指定。
image.png

[詳細オプションを表示する] をクリックします。
l_147288799_194_01d893b21ddb6b4c6f94aaee2badc0ba.png

[method] で "GET" を選択します。
l_147288799_193_7703a7cab797b3770f7b6c323965f181.png

アクション作成

[+ 新しいステップ] をクリック。
l_147288799_195_8ca8f510221da877d5de0dfcf68db8f5.png

"Http 要求の受信時" で受けた Get のリクエストに応じて WOFF を表示するために、[応答] のアクションを追加します。
一覧から探すか、または検索して [要求] を選択し、[応答] のアクションを指定してください。
l_147288799_181_ed0bed98cdbf8f86f6884dad2703b483.png

l_147288799_182_66bf83f05cf08e08b2b4564a5f289b32.png

[応答] のアクションが追加されました。
l_147288799_196_b40fd63af2743aade8c9abc213ed146c.png

各項目を以下のとおり指定します。

ヘッダーは以下のとおりです。

キー:

Content-Type

値:

text/html; charset=UTF-8

本文は以下をコピー、ペーストしてください。

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>devCamp Boost ハンズオン</title>
<script>
// WOFF ID を書き換えてください
const WOFF_ID = "i658h0DFhT-mSlGssQa6_Q";
// HTTP POST の URL を書き換えてください
const url = "https://prod-13.japaneast.logic.azure.com:443/workflows/4f8b1e46a6df44e1b48b0939a1e62f35/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=lrPlc5_GGqRmHuux_XVD7VU8TsnKss2yr7N2zmTOmwc";
</script>
    <script charset="utf-8" src="https://static.worksmobile.net/static/wm/woff/edge/3.6/sdk.js"></script>
    <style>
        /* Global Styles */
        body {
            font-family: 'Arial', sans-serif;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        h1 {
            margin-bottom: 15px;
        }

        input, select, button {
            width: 100%;
            margin-bottom: 15px;
            padding: 10px;
            box-sizing: border-box;
            font-size: 16px;
        }

        /* Toggle Switch CSS */
        .switch {
            position: relative;
            width: 60px;
            height: 34px;
        }

        .switch input { 
            opacity: 0;
            width: 0;
            height: 0;
        }

        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            transition: .4s;
        }

        .slider:before {
            position: absolute;
            content: "";
            height: 26px;
            width: 26px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            transition: .4s;
        }

        input:checked + .slider {
            background-color: #2196F3;
        }

        input:checked + .slider:before {
            transform: translateX(26px);
        }

        .slider.round {
            border-radius: 34px;
        }

        .slider.round:before {
            border-radius: 50%;
        }

        /* Label for Toggle */
        label {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 100%;
        }
    </style>
</head>
<body>
<h1>devCamp Boost</h1>

<label for="displayNameInput">表示名:</label>
<input type="text" id="displayNameInput" placeholder="名前を入力" required>

<label for="dateInput">日付:</label>
<input type="date" id="dateInput" required>

<label for="timeInput">開始時刻:</label>
<input type="time" id="timeInput" required>

<label for="workTypeSelect">作業種別:</label>
<select id="workTypeSelect">
    <option value="組み立て">組み立て</option>
    <option value="検査">検査</option>
    <option value="洗浄">洗浄</option>
    <option value="塗装">塗装</option>
</select>

<label>
    位置情報を送信: 
    <div class="switch">
        <input type="checkbox" id="locationToggle">
        <span class="slider round"></span>
    </div>
</label>

<button onclick="sendData()">送信</button>

    <script>
        document.addEventListener("DOMContentLoaded", function() {
            woff.init({
                woffId: WOFF_ID
            })
            .then(() => {
                return woff.getProfile();
            })
            .then(profile => {
                const input = document.getElementById("displayNameInput");
                input.value = profile.displayName;
            })
            .catch(err => {
                console.log(err.code, err.message);
            });
        });

        function getLocation() {
            return new Promise((resolve, reject) => {
                if (!navigator.geolocation) {
                    reject(new Error("Geolocation is not supported by your browser."));
                } else {
                    navigator.geolocation.getCurrentPosition(
                        position => {
                            resolve({
                                lat: position.coords.latitude,
                                lng: position.coords.longitude
                            });
                        },
                        error => {
                            reject(new Error("Unable to retrieve your location."));
                        }
                    );
                }
            });
        }

        async function sendData() {
            const displayNameValue = document.getElementById("displayNameInput").value;
            const dateValue = document.getElementById("dateInput").value;
            const timeValue = document.getElementById("timeInput").value;
            const workTypeValue = document.getElementById("workTypeSelect").value;
            const locationToggle = document.getElementById("locationToggle").checked;
            let locationData = null;

            if (locationToggle) {
                try {
                    locationData = await getLocation();
                } catch (err) {
                    console.error(err.message);
                    return;
                }
            }

            const data = {
                displayName: displayNameValue,
                date: dateValue,
                time: timeValue,
                workType: workTypeValue,
                location: locationData
            };



            fetch(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            })
            .then(response => {
                if (response.ok) {
                    woff.closeWindow();
                } else {
                    return response.json();
                }
            })
            .then(dataResponse => {
                if (dataResponse) {
                    console.log(dataResponse);
                }
            })
            .catch(error => {
                console.error('Error:', error);
            });
        }
    </script>
</body>
</html>

WOFF ID と HTTP POST の URL

以下の部分は後ほど書き換えます。

// WOFF ID を書き換えてください
const WOFF_ID = "i658h0DFhT-mSlGssQa6_Q";
// HTTP POST の URL を書き換えてください
const url = "https://prod-13.japaneast.logic.azure.com:443/workflows/4f8b1e46a6df44e1b48b0939a1e62f35/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=lrPlc5_GGqRmHuux_XVD7VU8TsnKss2yr7N2zmTOmwc";

[保存] をクリックします。
l_147288799_185_45a3436af6fb589bf4f779078b611a43.png

"HTTP 要求の受信時" の "HTTP POST の URL" が生成されているので、コピーボタンをクリックし、いずれかの場所にメモしてください。
l_147288799_186_5acb734325516d8e82c476ec7de90d75.png

LINE WORKS Developer Console で WOFF アプリ登録

LINE WORKS Developer Console にアクセスします。
https://dev.worksmobile.com/jp/console/openapi/v2/app/list/view

ご自分の LINE WORKS ID の割り当てられたアプリをクリックしてください。
l_147288799_337_ce4283f5454593f215270207e042bda9.png

WOFFアプリで [登録] ボタンをクリック。
l_147288799_188_b9761640c2522b6c793d4908b3573392.png

WOFF名: 任意の名前を指定
Endpoint URL を PowerAutomate で生成された HTTP 要求の受信時の URL を指定
サイズ: [Tall] を選択

[保存] ボタンをクリックしてください。
l_147288799_189_d298ebf8a6090fa2f2a4d26a2a6504fa.png

WOFF ID をコピーします。
image.png

[応答] アクションの本文の WOFF ID を書き換えてください。
l_147288799_295_d9ecebddfc57a19fdb61372ebb6e238a.png

[保存] してください。
l_147288799_296_b4b49d490bc6c80d54335308c83272d6.png

動作確認

WOFF アプリの [URL] コピー ボタンをクリックします。
l_147288799_190_e75690d9382079a5e9d743415e764cb6.png

コピーした URL を LINE WORKS のトークで自分に送ります。
l_217128028_5_a601005897c9ea57ec7608d42a4b07fa.png

トークルームで URL をタップすると WOFF アプリが表示されます。
モバイルアプリで実行すると、[表示名] に WOFF SDK で取得されたログイン中の LINE WORKS ID の表示名が既定値として入力された状態になります。
l_217128028_7_4eb67a1bfbb91ad7284889faef4b8eef.png

まだ正しく動作しないので、送信ボタンはタップしないでください。

おつかれさまでした。
このドキュメントの記述は以上です。

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?