<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>JavaScript | みんたく</title>
	<atom:link href="https://mintaku-blog.net/category/develop/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://mintaku-blog.net</link>
	<description>みんたくの技術ブログ</description>
	<lastBuildDate>Fri, 07 Jan 2022 15:22:58 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.11</generator>

<image>
	<url>https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2018/06/cropped-ipad-820272_640.jpg?fit=32%2C32&#038;ssl=1</url>
	<title>JavaScript | みんたく</title>
	<link>https://mintaku-blog.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">144480658</site>	<item>
		<title>JavaScriptの非同期処理(コールバック・Promise・async/await)について整理する</title>
		<link>https://mintaku-blog.net/js-async/</link>
					<comments>https://mintaku-blog.net/js-async/#respond</comments>
		
		<dc:creator><![CDATA[みんたく]]></dc:creator>
		<pubDate>Sun, 21 Feb 2021 04:54:17 +0000</pubDate>
				<category><![CDATA[まとめ系]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://mintaku-blog.net/?p=1853</guid>

					<description><![CDATA[<p>普段何気なく使っている技術や言葉について、表面的な知識にせず、しっかりとイメージできるまで自分なりに調べて整理し、理解するシリーズ。 JavaScript非 …</p>
The post <a href="https://mintaku-blog.net/js-async/">JavaScriptの非同期処理(コールバック・Promise・async/await)について整理する</a> first appeared on <a href="https://mintaku-blog.net">みんたく</a>.]]></description>
										<content:encoded><![CDATA[<p>普段何気なく使っている技術や言葉について、表面的な知識にせず、しっかりとイメージできるまで自分なりに調べて整理し、理解するシリーズ。</p>
<h2>JavaScript非同期処理が可能で並行処理はできない</h2>
<p>JavaScriptはシングルスレッドで動いており、並行処理はできません。</p>
<p>JavaScriptでは、キューに登録された関数が順番にひとつずつ実行され、その順番は同期や非同期であったりします。</p>
<p>この非同期というのは、サーバーと通信を行いリクエストが返るのを待っている間など、その処理を待たないで次へ進めることです。</p>
<p>&nbsp;</p>
<h2>コールバック</h2>
<h3>コールバックとは</h3>
<p>コールバックとは、処理が終わったら指定した関数が呼ばれる方法です。関数の引数に別の関数を指定する感じです。</p>
<p>最近のモダンな開発ではコールバックを使うことはほとんどありませんが、JavaScriptにおける非同期処理を理解する上でもコールバックについて理解する必要があります。</p>
<h3>コールバック関数/高階関数による処理</h3>
<p>引数として渡される関数のことをコールバック関数と呼び、別の関数を引数にとる関数を高階関数と呼びます。</p>
<p>以下の例では、showPrice関数を引数としてbicycle関数を呼び出しています。この場合ですとshowPrice関数がコールバック関数となり、bicycle関数が高階関数となります。</p><pre class="crayon-plain-tag">function bicycle(price, func){
  const name = '自転車';
  func(name, price);
}

const showPrice = function(name, price){
  console.log(name + ' の現在価格は ' + price + ' 円です。');
}

bicycle(20000, showPrice);</pre><p>&nbsp;</p>
<p>コールバック関数は、引数に直接記述することも可能です。</p><pre class="crayon-plain-tag">function bicycle(price, func){
  const name = '自転車';
  func(name, price);
}

bicycle(20000, function(name, price){
  console.log(name + ' の現在価格は ' + price + ' 円です。');
});</pre><p>&nbsp;</p>
<h3>コールバック地獄</h3>
<p>例えば、いくつかのファイルの読み込みが終わった後にそのデータに対して処理をしたい場合、以下のようにコールバック関数を次々に書いていくことになります。</p>
<p>この例では3つファイルに対して処理をかけていますが、これがどんどん増えていくとさらにネストが深くなることで可読性が下がり、メンテナンスが大変になります。</p><pre class="crayon-plain-tag">const fs = require('fs');

fs.readFile(a.txt', function(resA) {
  fs.readFile(b.txt', function(resB) {
    fs.readFile(c.txt', function(resC) {
      console.log(resA + resB + resC);
    })
  })
})</pre><p>&nbsp;</p>
<p>また、エラー処理を個別に書いていくとさらにコードが複雑化していきます。</p><pre class="crayon-plain-tag">const fs = require('fs');

fs.readFile('a.txt', function(err, resA) {
  if (err) {
    console.log(err);
    return;
  }
  fs.readFile('b.txt', function(err, resB) {
    if (err) {
      console.log(err);
      return;
    }
    fs.readFile('c.txt', function(err, resC) {
      if (err) {
        console.log(err);
        return;
      }
      console.log(resA + resB + resC);
    })
  })
})</pre><p>この非同期処理におけるコールバック地獄を解消するためにPromiseがES2015で導入されました。</p>
<p>&nbsp;</p>
<h2>Promise</h2>
<h3>Promiseとは</h3>
<p>Promiseとは、JavaScriptでの非同期処理のコールバック関数をより簡潔に記述するための仕組みです。</p>
<p>Promise を用いることで、非同期処理の成功や失敗に対するハンドラーを関連付けることができます。これにより非同期処理のメソッドは、最終的な値を返すのではなく、未来のある時点で値を持つPromiseを返すことで、同期メソッドと同じように値を返すことができるようになります。</p>
<p>Promiseはその名の通り「今は値を返せないけどあとでちゃんと返すよ」と約束するオブジェクトです。</p>
<h3>Promiseの状態</h3>
<p>Promise の状態は以下のいずれかとなります。</p>
<p>初期状態はpendingで、一度fulfilledまたはrejectedになったらそれ以降は状態は変わらず、非同期処理の終了時に返す値もそれ以降は変わりません。</p>
<ul>
<li>pending : まだ処理が終わっていない状態</li>
<li>fulfilled : 処理が成功した状態</li>
<li>rejected : 処理が失敗した状態</li>
</ul>
<p>&nbsp;</p>
<h3>Promiseの使い方</h3>
<h4>resolve, reject</h4>
<p></p><pre class="crayon-plain-tag">new Promise(function(resolve, reject) {
  resolve('success');
});

new Promise(function(resolve, reject) {
  reject('failed');
});</pre><p>Promiseはresolveとreject、2つの関数を引数に取ります。</p>
<ul>
<li>resolve : 処理が成功したときのメッセージを表示する関数</li>
<li>reject : 処理が失敗したときのメッセージを表示する関数</li>
</ul>
<h4>then(), catch()</h4>
<h5>Promise#then(onFulfilled, onRejected)</h5>
<p>then()は2つの関数を引数に取ります。Promiseの状態がfulfilledになったら1番目が、rejectedになったら2番目のコールバック関数が実行されます。</p>
<h5>Promise#catch(onRejected)</h5>
<p>then(undefined, onRejected) のショートカットとして機能し、返り値 promiseで引数の onRejectedのコールバック関数が実行されます。</p>
<p>公式にもありましたが、エラー処理がすぐに必要がない場合は、最後の.catch() 文までエラー処理をしない方がシンプルに書くことができます。</p>
<p>参考：</p>
<p>
<div class="ys-blog-card">
	<div class="ys-blog-card__container">
				<div class="ys-blog-card__text">
			<p class="ys-blog-card__title">
				<a class="ys-blog-card__link" href="https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise - JavaScript | MDN</a>
			</p>
							<div class="ys-blog-card__dscr">
					Promise オブジェクトは、非同期処理の完了（もしくは失敗）の結果およびその&hellip;				</div>
										<div class="ys-blog-card__domain">developer.mozilla.org</div>
					</div>
	</div>
</div>
<br />
<pre class="crayon-plain-tag">const myPromise =
  (new Promise(myExecutorFunc))
  .then(handleFulfilledA,handleRejectedA)
  .then(handleFulfilledB,handleRejectedB)
  .then(handleFulfilledC,handleRejectedC);

// または、おそらく次の方がよい ...

const myPromise =
  (new Promise(myExecutorFunc))
  .then(handleFulfilledA)
  .then(handleFulfilledB)
  .then(handleFulfilledC)
  .catch(handleRejectedAny);</pre><br />
&nbsp;</p>
<h3>Promiseによる非同期処理</h3>
<p>以上を踏まえて、先程のコールバック地獄をPromiseで書き換えると以下のようになります。だいぶスッキリして見やすくなりました。</p><pre class="crayon-plain-tag">let a, b, c

readFile('a.txt')
.then(function(resA) {
    a = resA;
    return readFile('b.txt');
})
.then(function(resB) {
  b = resB;
  return readFile('c.txt');
})
.then(function(resC) {
  c = resC;
  console.log(a + b + c);
})
.catch(function(err) {
  console.log(err);
})</pre><p>&nbsp;</p>
<h2>async/await</h2>
<h3>async/awaitとは</h3>
<p>async/awaitは非同期処理の構文のことで、Promiseを利用した場合よりも、簡潔に非同期処理を書くことができます。</p>
<h3>asyncとは</h3>
<p>asyncとは、非同期関数を定義する関数宣言のことで、以下のように関数の前にasyncを宣言することにより、非同期の関数を定義できます。</p>
<p>async functionはPromiseを返却します。</p><pre class="crayon-plain-tag">async function getSuccess() {
  return 'success'
}</pre><p>&nbsp;</p>
<p>ちなみにPromiseで書くと以下のようになります。</p><pre class="crayon-plain-tag">function getSuccess() {
  return Promise.resolve('success')
}</pre><p>&nbsp;</p>
<h3>awaitとは</h3>
<p>async function内でPromiseの結果が返ってくるまで待機する演算子のことです。</p>
<p>awaitを指定した関数のPromiseの結果が返されるまで、async function内の処理を一時停止し、結果が返されたらasync function内の処理を再開します。</p><pre class="crayon-plain-tag">async function showResult() {
  const result = await getResult();

  // getResult()のPromiseの結果が返ってきてから実行される
  console.log(result);
}</pre><p>&nbsp;</p>
<h3>async/awaitによる非同期処理</h3>
<p>以上を踏まえて先程のコードをasync/awaitで書き直してみます。</p>
<p>Promiseよりもさらにわかりやすくスッキリなりました。</p><pre class="crayon-plain-tag">async function showFilesData() {
  const resA = await readFile(a.txt');
  const resB = await readFile(b.txt');
  const resC = await readFile(c.txt');
  console.log(resA + resB + resC);
}

showFilesData()
.catch(err) {console.log(err)}</pre><p>&nbsp;</p>
<h2>参考</h2>
<p>
<div class="ys-blog-card">
	<div class="ys-blog-card__container">
				<div class="ys-blog-card__text">
			<p class="ys-blog-card__title">
				<a class="ys-blog-card__link" href="https://knowledge.sakura.ad.jp/24888/">JavaScriptの非同期処理を理解する その1 〜コールバック編〜  |  さくらのナレッジ</a>
			</p>
										<div class="ys-blog-card__domain">knowledge.sakura.ad.jp</div>
					</div>
	</div>
</div>
<br />

<div class="ys-blog-card">
	<div class="ys-blog-card__container">
					<figure class="ys-blog-card__image">
				<img src="https://i0.wp.com/www.javadrive.jp/javascript/function/img/p16-0.png?w=800&#038;ssl=1" alt="" data-recalc-dims="1">			</figure>
				<div class="ys-blog-card__text">
			<p class="ys-blog-card__title">
				<a class="ys-blog-card__link" href="https://www.javadrive.jp/javascript/function/index16.html">JavaScript | コールバック関数/高階関数を利用する</a>
			</p>
							<div class="ys-blog-card__dscr">
					JavaScript では関数もオブジェクトのひとつであり、関数を呼びだす時に引&hellip;				</div>
										<div class="ys-blog-card__domain">www.javadrive.jp</div>
					</div>
	</div>
</div>
<br />

<div class="ys-blog-card">
	<div class="ys-blog-card__container">
					<figure class="ys-blog-card__image">
				<img src="https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-afbab5eb44e0b055cce1258705637a91.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLXByb2ZpbGUtaW1hZ2VzLmltZ2l4Lm5ldC9odHRwcyUzQSUyRiUyRnFpaXRhLWltYWdlLXN0b3JlLnMzLmFtYXpvbmF3cy5jb20lMkYwJTJGMjAxOTMlMkZwcm9maWxlLWltYWdlcyUyRjE0NzM2ODI5NDE_aXhsaWI9cmItNC4wLjAmYXI9MSUzQTEmZml0PWNyb3AmbWFzaz1lbGxpcHNlJmJnPUZGRkZGRiZmbT1wbmczMiZzPTM0ZTFkMjkwYzFjNmYxMjg1ZGVhZjgyYTViNDRkMWYw%26blend-x%3D120%26blend-y%3D467%26blend-w%3D82%26blend-h%3D82%26blend-mode%3Dnormal%26s%3D9e9c5c9e91f855499e797f6b31c138d6?ixlib=rb-4.0.0&amp;w=1200&amp;fm=jpg&amp;mark64=aHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTk2MCZoPTMyNCZ0eHQ9UHJvbWlzZSVFMyU4MSVBQiVFMyU4MSVBNCVFMyU4MSU4NCVFMyU4MSVBNjAlRTMlODElOEIlRTMlODIlODklRTUlOEIlODklRTUlQkMlQjclRTMlODElOTclRTMlODElQTYlRTMlODElQkYlRTMlODElOUYmdHh0LWFsaWduPWxlZnQlMkN0b3AmdHh0LWNvbG9yPSUyMzFFMjEyMSZ0eHQtZm9udD1IaXJhZ2lubyUyMFNhbnMlMjBXNiZ0eHQtc2l6ZT01NiZ0eHQtcGFkPTAmcz1iNWZhNjFmNmJjYzUyOTcyY2MwOWM2ZWQ4MGQ0NTFiZA&amp;mark-x=120&amp;mark-y=112&amp;blend64=aHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTgzOCZoPTU4JnR4dD0lNDB0b3NoaWhpcm9jayZ0eHQtY29sb3I9JTIzMUUyMTIxJnR4dC1mb250PUhpcmFnaW5vJTIwU2FucyUyMFc2JnR4dC1zaXplPTM2JnR4dC1wYWQ9MCZzPTExNTdkZGIzNTgzZDI2MmEwOTc1YTQ4ODE2ZjdlZDIw&amp;blend-x=242&amp;blend-y=480&amp;blend-w=838&amp;blend-h=46&amp;blend-fit=crop&amp;blend-crop=left%2Cbottom&amp;blend-mode=normal&amp;s=d39b66de3a7100b079c98228bed90302" alt="">			</figure>
				<div class="ys-blog-card__text">
			<p class="ys-blog-card__title">
				<a class="ys-blog-card__link" href="https://qiita.com/toshihirock/items/e49b66f8685a8510bd76">Promiseについて0から勉強してみた #JavaScript - Qiita</a>
			</p>
							<div class="ys-blog-card__dscr">
					ES6を使う機会がありそうで、Promiseについて全然知らなかったので、実際に&hellip;				</div>
										<div class="ys-blog-card__domain">qiita.com</div>
					</div>
	</div>
</div>
<br />

<div class="ys-blog-card">
	<div class="ys-blog-card__container">
					<figure class="ys-blog-card__image">
				<img src="https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-afbab5eb44e0b055cce1258705637a91.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLXByb2ZpbGUtaW1hZ2VzLmltZ2l4Lm5ldC9odHRwcyUzQSUyRiUyRnMzLWFwLW5vcnRoZWFzdC0xLmFtYXpvbmF3cy5jb20lMkZxaWl0YS1pbWFnZS1zdG9yZSUyRjAlMkY1Mjc4MjIlMkY3NWNiOTJmMjJkNjk3NzRjZmE0NTVmMzY0MjllMjVlNTIwMzc5ODg4JTJGeF9sYXJnZS5wbmclM0YxNTcyOTQ5MTM2P2l4bGliPXJiLTQuMC4wJmFyPTElM0ExJmZpdD1jcm9wJm1hc2s9ZWxsaXBzZSZiZz1GRkZGRkYmZm09cG5nMzImcz05NTZlMDFhN2UwMmIzZjY1ZDAyNjEyNjJkNmQzOGUwMA%26blend-x%3D120%26blend-y%3D467%26blend-w%3D82%26blend-h%3D82%26blend-mode%3Dnormal%26s%3D1483c41d474beb517a82029b5d48d99f?ixlib=rb-4.0.0&amp;w=1200&amp;fm=jpg&amp;mark64=aHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTk2MCZoPTMyNCZ0eHQ9JUUzJTgyJUIzJUUzJTgzJUJDJUUzJTgzJUFCJUUzJTgzJTkwJUUzJTgzJTgzJUUzJTgyJUFGJUU1JTlDJUIwJUU3JThEJTg0JUUzJTgxJThCJUUzJTgyJTg5JUUzJTgxJUFFJUU4JTg0JUIxJUU1JTg3JUJBJnR4dC1hbGlnbj1sZWZ0JTJDdG9wJnR4dC1jb2xvcj0lMjMxRTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9NTYmdHh0LXBhZD0wJnM9MjZmNzg4Mjg3NzhhNjg1Mjk0NTZkMDg3YTk1OWJkOTc&amp;mark-x=120&amp;mark-y=112&amp;blend64=aHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTgzOCZoPTU4JnR4dD0lNDB1bWVrbzIwMTUmdHh0LWNvbG9yPSUyMzFFMjEyMSZ0eHQtZm9udD1IaXJhZ2lubyUyMFNhbnMlMjBXNiZ0eHQtc2l6ZT0zNiZ0eHQtcGFkPTAmcz1jMzYxODc1OTVjMGY4NzlhNGMwYWExNzU3YmY2OGY3OQ&amp;blend-x=242&amp;blend-y=480&amp;blend-w=838&amp;blend-h=46&amp;blend-fit=crop&amp;blend-crop=left%2Cbottom&amp;blend-mode=normal&amp;s=b2032d5d38143910548914d68f6cbaa0" alt="">			</figure>
				<div class="ys-blog-card__text">
			<p class="ys-blog-card__title">
				<a class="ys-blog-card__link" href="https://qiita.com/umeko2015/items/2fdb2785eac8f4117f23">コールバック地獄からの脱出 #JavaScript - Qiita</a>
			</p>
							<div class="ys-blog-card__dscr">
					どうもこんにちは。うめきです。 これはアドベントカレンダー「厚木の民」の３日目の&hellip;				</div>
										<div class="ys-blog-card__domain">qiita.com</div>
					</div>
	</div>
</div>
<br />

<div class="ys-blog-card">
	<div class="ys-blog-card__container">
				<div class="ys-blog-card__text">
			<p class="ys-blog-card__title">
				<a class="ys-blog-card__link" href="https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise - JavaScript | MDN</a>
			</p>
							<div class="ys-blog-card__dscr">
					Promise オブジェクトは、非同期処理の完了（もしくは失敗）の結果およびその&hellip;				</div>
										<div class="ys-blog-card__domain">developer.mozilla.org</div>
					</div>
	</div>
</div>
<br />

<div class="ys-blog-card">
	<div class="ys-blog-card__container">
					<figure class="ys-blog-card__image">
				<img src="https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-afbab5eb44e0b055cce1258705637a91.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLXByb2ZpbGUtaW1hZ2VzLmltZ2l4Lm5ldC9odHRwcyUzQSUyRiUyRnFpaXRhLWltYWdlLXN0b3JlLnMzLmFtYXpvbmF3cy5jb20lMkYwJTJGNjk2NjclMkZwcm9maWxlLWltYWdlcyUyRjE0NzM2OTgyMjY_aXhsaWI9cmItNC4wLjAmYXI9MSUzQTEmZml0PWNyb3AmbWFzaz1lbGxpcHNlJmJnPUZGRkZGRiZmbT1wbmczMiZzPTQzZTJhNjU1NjIwNzk4M2IzYTc2YjY4NGU5ZmUyOWUx%26blend-x%3D120%26blend-y%3D467%26blend-w%3D82%26blend-h%3D82%26blend-mode%3Dnormal%26s%3D8b15819f9ec6d7d0017d62c56e74ff55?ixlib=rb-4.0.0&amp;w=1200&amp;fm=jpg&amp;mark64=aHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTk2MCZoPTMyNCZ0eHQ9YXN5bmMlMkZhd2FpdCUyMCVFNSU4NSVBNSVFOSU5NiU4MCVFRiVCQyU4OEphdmFTY3JpcHQlRUYlQkMlODkmdHh0LWFsaWduPWxlZnQlMkN0b3AmdHh0LWNvbG9yPSUyMzFFMjEyMSZ0eHQtZm9udD1IaXJhZ2lubyUyMFNhbnMlMjBXNiZ0eHQtc2l6ZT01NiZ0eHQtcGFkPTAmcz04MWQ2YzQyMjA0YjI3OWVlMTJlMWU0NzI3MDZmZjUxYw&amp;mark-x=120&amp;mark-y=112&amp;blend64=aHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTgzOCZoPTU4JnR4dD0lNDBzb2FyZmxhdCZ0eHQtY29sb3I9JTIzMUUyMTIxJnR4dC1mb250PUhpcmFnaW5vJTIwU2FucyUyMFc2JnR4dC1zaXplPTM2JnR4dC1wYWQ9MCZzPTM5NDY1YjE3ODAxYmIyM2NmYjZiNDFiNDQ1NjNlNTMz&amp;blend-x=242&amp;blend-y=480&amp;blend-w=838&amp;blend-h=46&amp;blend-fit=crop&amp;blend-crop=left%2Cbottom&amp;blend-mode=normal&amp;s=977d67146ee3b129fae62b72acabe360" alt="">			</figure>
				<div class="ys-blog-card__text">
			<p class="ys-blog-card__title">
				<a class="ys-blog-card__link" href="https://qiita.com/soarflat/items/1a9613e023200bbebcb3">async/await 入門（JavaScript） #AsyncAwait - Qiita</a>
			</p>
							<div class="ys-blog-card__dscr">
					はじめに 今更ですが、JavaScriptのasync/awaitに関する備忘録&hellip;				</div>
										<div class="ys-blog-card__domain">qiita.com</div>
					</div>
	</div>
</div>
</p>The post <a href="https://mintaku-blog.net/js-async/">JavaScriptの非同期処理(コールバック・Promise・async/await)について整理する</a> first appeared on <a href="https://mintaku-blog.net">みんたく</a>.]]></content:encoded>
					
					<wfw:commentRss>https://mintaku-blog.net/js-async/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1853</post-id>	</item>
		<item>
		<title>【LINE謎】LINEで遊べる謎解きの作り方と開発方法まとめ</title>
		<link>https://mintaku-blog.net/line-mystery/</link>
					<comments>https://mintaku-blog.net/line-mystery/#respond</comments>
		
		<dc:creator><![CDATA[みんたく]]></dc:creator>
		<pubDate>Fri, 08 May 2020 05:42:04 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[個人開発]]></category>
		<category><![CDATA[その他]]></category>
		<guid isPermaLink="false">https://mintaku-blog.net/?p=1457</guid>

					<description><![CDATA[<p>LINE謎のBotを作成する上で、以下の記事や本を参考にしました。 参考：LINE謎の開発についてまとめ 参考：プログラミング初心者でも無料で簡単にLINE …</p>
The post <a href="https://mintaku-blog.net/line-mystery/">【LINE謎】LINEで遊べる謎解きの作り方と開発方法まとめ</a> first appeared on <a href="https://mintaku-blog.net">みんたく</a>.]]></description>
										<content:encoded><![CDATA[<p>LINE謎のBotを作成する上で、以下の記事や本を参考にしました。</p>
<p>参考：<a href="https://qiita.com/acerolaproduction/items/d89b51a7ae7b3f18370e" target="_blank" rel="noopener noreferrer">LINE謎の開発についてまとめ</a></p>
<p>参考：<a href="https://note.com/tatsuaki_w/n/nfed622429f4a" target="_blank" rel="noopener noreferrer">プログラミング初心者でも無料で簡単にLINE BOTが作れるチュートリアル｜渡なべ<img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f372.png" alt="🍲" class="wp-smiley" style="height: 1em; max-height: 1em;" />達明｜note</a></p>
<p>参考：<a href="https://qiita.com/mick_k1218/items/0ceb411f63a298decad2" target="_blank" rel="noopener noreferrer">【入門】Google Apps ScriptでLINE botを作成する</a></p>
<p>特にこちらのKindle本ではとてもわかりやすく解説されています。こちらの本では実際に作られている謎解きやマーケティング戦略まで紹介されているので、ご一読することをおすすめします。</p>
<p><iframe loading="lazy" title="ゼロから始めて1万人に遊ばれた謎解きゲームの作り方からマーケティングまで: ~LINE bot編~" type="text/html" width="800" height="550" frameborder="0" allowfullscreen style="max-width:100%" src="https://read.amazon.com.au/kp/card?preview=inline&#038;linkCode=kpd&#038;ref_=k4w_oembed_05NwxO9luBkiId&#038;asin=B07YK39CY9&#038;tag=kpembed-20"></iframe></p>
<h2>LINE謎とは</h2>
<p>LINEの公式アカウントを用いて、主にBot形式で謎を出題する謎解き形式をLINE謎と呼ばれています。</p>
<p>LINEのアカウントさえあれば、手軽に謎解きに挑戦することができます。LINEのMessaging APIが開放されてからLINE謎が出現し、少しずつ広まってきているようです。</p>
<h2>LINE謎開発の事前準備</h2>
<p>事前準備として以下が必要となります。今回は参考記事通りにGAS(Google App Script)を使用してコーディングを行っています。Googleアカウントは登録された前提とします。</p>
<ul>
<li>Googleアカウント登録</li>
<li>LINE Developers登録</li>
<li>LINE Bot Designer(必須ではない)</li>
</ul>
<h3>LINE Developersの登録</h3>
<p><img data-attachment-id="1458" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-07-18-25-43/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/cc9ee2ab3f1006ca700e7e4e39e79772.png?fit=2786%2C1500&amp;ssl=1" data-orig-size="2786,1500" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-07 18.25.43" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/cc9ee2ab3f1006ca700e7e4e39e79772.png?fit=300%2C162&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/cc9ee2ab3f1006ca700e7e4e39e79772.png?fit=800%2C430&amp;ssl=1" loading="lazy" class="aligncenter size-large wp-image-1458" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/cc9ee2ab3f1006ca700e7e4e39e79772.png?resize=800%2C430&#038;ssl=1" alt="" width="800" height="430" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/cc9ee2ab3f1006ca700e7e4e39e79772.png?resize=1024%2C551&amp;ssl=1 1024w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/cc9ee2ab3f1006ca700e7e4e39e79772.png?resize=300%2C162&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/cc9ee2ab3f1006ca700e7e4e39e79772.png?resize=768%2C413&amp;ssl=1 768w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/cc9ee2ab3f1006ca700e7e4e39e79772.png?resize=1536%2C827&amp;ssl=1 1536w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/cc9ee2ab3f1006ca700e7e4e39e79772.png?resize=2048%2C1103&amp;ssl=1 2048w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/cc9ee2ab3f1006ca700e7e4e39e79772.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/cc9ee2ab3f1006ca700e7e4e39e79772.png?w=2400&amp;ssl=1 2400w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<p>まず、以下のリンクからLINE開発者登録を行います。既にLINEアカウントを持っている場合は、そのアカウントで登録することができます。QRコードログインで簡単に認証することができます。</p>
<p><a href="https://developers.line.me/ja/" target="_blank" rel="noopener noreferrer">LINE Developers</a></p>
<p><img data-attachment-id="1459" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-07-18-30-20/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/88cf9f06458d1fc3e26ace49a91920a4.png?fit=1104%2C1198&amp;ssl=1" data-orig-size="1104,1198" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-07 18.30.20" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/88cf9f06458d1fc3e26ace49a91920a4.png?fit=276%2C300&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/88cf9f06458d1fc3e26ace49a91920a4.png?fit=800%2C868&amp;ssl=1" loading="lazy" class="aligncenter size-large wp-image-1459" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/88cf9f06458d1fc3e26ace49a91920a4.png?resize=800%2C868&#038;ssl=1" alt="" width="800" height="868" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/88cf9f06458d1fc3e26ace49a91920a4.png?resize=944%2C1024&amp;ssl=1 944w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/88cf9f06458d1fc3e26ace49a91920a4.png?resize=276%2C300&amp;ssl=1 276w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/88cf9f06458d1fc3e26ace49a91920a4.png?resize=768%2C833&amp;ssl=1 768w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/88cf9f06458d1fc3e26ace49a91920a4.png?w=1104&amp;ssl=1 1104w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<h3>LINE Bot Designerのダウンロード</h3>
<p>LINE Bot Designerを使用することで、簡単かつ短時間でLINE Botのプロトタイプを作成することができます。GUIで感覚的にチャットボットを設計できます。</p>
<p>以下のリンクからLINE Bot Designerをダウンロードします。後ほど使用しますので、その後インストールまでやっておきましょう。</p>
<p><a href="https://developers.line.biz/ja/services/bot-designer/" target="_blank" rel="noopener noreferrer">LINE Bot Designer</a></p>
<h2>Messaging APIで新規チャンネルを作成</h2>
<p><img data-attachment-id="1464" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-07-20-53-19/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/058a48c08bd98f266eb318748037874d.png?fit=2568%2C974&amp;ssl=1" data-orig-size="2568,974" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-07 20.53.19" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/058a48c08bd98f266eb318748037874d.png?fit=300%2C114&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/058a48c08bd98f266eb318748037874d.png?fit=800%2C303&amp;ssl=1" loading="lazy" class="aligncenter size-large wp-image-1464" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/058a48c08bd98f266eb318748037874d.png?resize=800%2C303&#038;ssl=1" alt="" width="800" height="303" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/058a48c08bd98f266eb318748037874d.png?resize=1024%2C388&amp;ssl=1 1024w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/058a48c08bd98f266eb318748037874d.png?resize=300%2C114&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/058a48c08bd98f266eb318748037874d.png?resize=768%2C291&amp;ssl=1 768w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/058a48c08bd98f266eb318748037874d.png?resize=1536%2C583&amp;ssl=1 1536w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/058a48c08bd98f266eb318748037874d.png?resize=2048%2C777&amp;ssl=1 2048w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/058a48c08bd98f266eb318748037874d.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/058a48c08bd98f266eb318748037874d.png?w=2400&amp;ssl=1 2400w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<p>先ほど登録したLINE Developersにログインし、「新規チャンネル作成」を押します。新規チャンネル作成に必要な項目を入力します。</p>
<p>ここで作成するLINE謎のチャンネル名やアイコンなどを登録します。なおチャンネル名は7日間は変更できないため、注意が必要です。</p>
<p><img data-attachment-id="1465" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-07-20-53-44/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/af938c8996b9fda0f27756efdb4df9b3.png?fit=2606%2C1434&amp;ssl=1" data-orig-size="2606,1434" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-07 20.53.44" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/af938c8996b9fda0f27756efdb4df9b3.png?fit=300%2C165&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/af938c8996b9fda0f27756efdb4df9b3.png?fit=800%2C440&amp;ssl=1" loading="lazy" class="aligncenter size-large wp-image-1465" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/af938c8996b9fda0f27756efdb4df9b3.png?resize=800%2C440&#038;ssl=1" alt="" width="800" height="440" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/af938c8996b9fda0f27756efdb4df9b3.png?resize=1024%2C563&amp;ssl=1 1024w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/af938c8996b9fda0f27756efdb4df9b3.png?resize=300%2C165&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/af938c8996b9fda0f27756efdb4df9b3.png?resize=768%2C423&amp;ssl=1 768w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/af938c8996b9fda0f27756efdb4df9b3.png?resize=1536%2C845&amp;ssl=1 1536w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/af938c8996b9fda0f27756efdb4df9b3.png?resize=2048%2C1127&amp;ssl=1 2048w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/af938c8996b9fda0f27756efdb4df9b3.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/af938c8996b9fda0f27756efdb4df9b3.png?w=2400&amp;ssl=1 2400w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<p>LINE Messaging API：<a href="https://developers.line.biz/ja/services/messaging-api/" target="_blank" rel="noopener noreferrer">Messaging APIの特徴 Messaging APIは</a></p>
<h2>GASからWebhook URLを取得する</h2>
<p>まず、自身のGoogleアカウントからGoogleドライブを開き、Googleスプレッドシートを新規作成します。</p>
<p>スプレッドシートを開いたら、「ツール」→「スクリプトエディタ」を選択します。</p>
<p><img data-attachment-id="1466" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-08-9-38-19/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/c051166aa032a1025cb3921cfcc04e31.png?fit=2768%2C1526&amp;ssl=1" data-orig-size="2768,1526" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-08 9.38.19" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/c051166aa032a1025cb3921cfcc04e31.png?fit=300%2C165&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/c051166aa032a1025cb3921cfcc04e31.png?fit=800%2C441&amp;ssl=1" loading="lazy" class="aligncenter size-large wp-image-1466" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/c051166aa032a1025cb3921cfcc04e31.png?resize=800%2C441&#038;ssl=1" alt="" width="800" height="441" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/c051166aa032a1025cb3921cfcc04e31.png?resize=1024%2C565&amp;ssl=1 1024w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/c051166aa032a1025cb3921cfcc04e31.png?resize=300%2C165&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/c051166aa032a1025cb3921cfcc04e31.png?resize=768%2C423&amp;ssl=1 768w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/c051166aa032a1025cb3921cfcc04e31.png?resize=1536%2C847&amp;ssl=1 1536w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/c051166aa032a1025cb3921cfcc04e31.png?resize=2048%2C1129&amp;ssl=1 2048w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/c051166aa032a1025cb3921cfcc04e31.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/c051166aa032a1025cb3921cfcc04e31.png?w=2400&amp;ssl=1 2400w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<p>&nbsp;</p>
<p>選択すると、以下のようなスクリプトエディタが表示されます。左上にあるプロジェクト名を入力し、「公開」→「ウェブアプリケーションとして導入」を選択してください。</p>
<p><img data-attachment-id="1467" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-08-9-38-36/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/824959a761429044914e86620f4b8beb.png?fit=1242%2C632&amp;ssl=1" data-orig-size="1242,632" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-08 9.38.36" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/824959a761429044914e86620f4b8beb.png?fit=300%2C153&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/824959a761429044914e86620f4b8beb.png?fit=800%2C407&amp;ssl=1" loading="lazy" class="aligncenter size-large wp-image-1467" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/824959a761429044914e86620f4b8beb.png?resize=800%2C407&#038;ssl=1" alt="" width="800" height="407" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/824959a761429044914e86620f4b8beb.png?resize=1024%2C521&amp;ssl=1 1024w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/824959a761429044914e86620f4b8beb.png?resize=300%2C153&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/824959a761429044914e86620f4b8beb.png?resize=768%2C391&amp;ssl=1 768w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/824959a761429044914e86620f4b8beb.png?w=1242&amp;ssl=1 1242w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<p>&nbsp;</p>
<p>それぞれ、以下のように設定し「Deploy」を押下します。</p>
<p><img data-attachment-id="2144" data-permalink="https://mintaku-blog.net/line-mystery/line-deploy/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/line-deploy.png?fit=892%2C798&amp;ssl=1" data-orig-size="892,798" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="line-deploy" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/line-deploy.png?fit=300%2C268&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/line-deploy.png?fit=800%2C716&amp;ssl=1" loading="lazy" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/line-deploy.png?resize=800%2C716&#038;ssl=1" alt="" width="800" height="716" class="aligncenter size-full wp-image-2144" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/line-deploy.png?w=892&amp;ssl=1 892w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/line-deploy.png?resize=300%2C268&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/line-deploy.png?resize=768%2C687&amp;ssl=1 768w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<p>&nbsp;</p>
<p>表示された「Current web app URL」をコピーします。これがWebhook URLとなります。</p>
<p><img data-attachment-id="1469" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-08-9-45-47/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/657511a77d377aee9c19daa20d6f1ab8.png?fit=886%2C526&amp;ssl=1" data-orig-size="886,526" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-08 9.45.47" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/657511a77d377aee9c19daa20d6f1ab8.png?fit=300%2C178&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/657511a77d377aee9c19daa20d6f1ab8.png?fit=800%2C475&amp;ssl=1" loading="lazy" class="aligncenter size-full wp-image-1469" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/657511a77d377aee9c19daa20d6f1ab8.png?resize=800%2C475&#038;ssl=1" alt="" width="800" height="475" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/657511a77d377aee9c19daa20d6f1ab8.png?w=886&amp;ssl=1 886w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/657511a77d377aee9c19daa20d6f1ab8.png?resize=300%2C178&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/657511a77d377aee9c19daa20d6f1ab8.png?resize=768%2C456&amp;ssl=1 768w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<h2>LINE DevelopersのWebhook設定でGASと連携する</h2>
<p>作成したチャンネルからMessaging API設定を選択します。下にあるWebhook設定のWebhook URLに先ほどコピーしたURLをペーストします。また、Webhookの利用をONにします。</p>
<p><img data-attachment-id="1470" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-08-9-51-42/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/61d6c3c8d15c2511791f9eb4f159a699.png?fit=2116%2C788&amp;ssl=1" data-orig-size="2116,788" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-08 9.51.42" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/61d6c3c8d15c2511791f9eb4f159a699.png?fit=300%2C112&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/61d6c3c8d15c2511791f9eb4f159a699.png?fit=800%2C298&amp;ssl=1" loading="lazy" class="aligncenter size-large wp-image-1470" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/61d6c3c8d15c2511791f9eb4f159a699.png?resize=800%2C298&#038;ssl=1" alt="" width="800" height="298" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/61d6c3c8d15c2511791f9eb4f159a699.png?resize=1024%2C381&amp;ssl=1 1024w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/61d6c3c8d15c2511791f9eb4f159a699.png?resize=300%2C112&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/61d6c3c8d15c2511791f9eb4f159a699.png?resize=768%2C286&amp;ssl=1 768w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/61d6c3c8d15c2511791f9eb4f159a699.png?resize=1536%2C572&amp;ssl=1 1536w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/61d6c3c8d15c2511791f9eb4f159a699.png?resize=2048%2C763&amp;ssl=1 2048w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/61d6c3c8d15c2511791f9eb4f159a699.png?w=1600&amp;ssl=1 1600w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<p>&nbsp;</p>
<p>次にさらに下にあるチャンネルアクセストークンの発行を行います。このチャンネルアクセストークンは後で使います。</p>
<p><img data-attachment-id="1471" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-08-9-57-05/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/1a9f273adb20a35baaabeed408a496b3.png?fit=1832%2C234&amp;ssl=1" data-orig-size="1832,234" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-08 9.57.05" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/1a9f273adb20a35baaabeed408a496b3.png?fit=300%2C38&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/1a9f273adb20a35baaabeed408a496b3.png?fit=800%2C102&amp;ssl=1" loading="lazy" class="aligncenter size-large wp-image-1471" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/1a9f273adb20a35baaabeed408a496b3.png?resize=800%2C102&#038;ssl=1" alt="" width="800" height="102" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/1a9f273adb20a35baaabeed408a496b3.png?resize=1024%2C131&amp;ssl=1 1024w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/1a9f273adb20a35baaabeed408a496b3.png?resize=300%2C38&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/1a9f273adb20a35baaabeed408a496b3.png?resize=768%2C98&amp;ssl=1 768w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/1a9f273adb20a35baaabeed408a496b3.png?resize=1536%2C196&amp;ssl=1 1536w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/1a9f273adb20a35baaabeed408a496b3.png?w=1832&amp;ssl=1 1832w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/1a9f273adb20a35baaabeed408a496b3.png?w=1600&amp;ssl=1 1600w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<h2>GAS(Google App Script)を使って、ユーザとの応答形式LINE Botのスクリプトを実装する</h2>
<p>GASの画面に戻り、ユーザとの応答形式のスクリプトを実装していきます。JavaScriptで書くことができます。</p>
<h3>チャンネルアクセストークンの設定とリクエスト判定</h3>
<p>まずはじめにチャンネルアクセストークンを設定します。先ほど発行したチャンネルアクセストークンを変数に代入しましょう。</p>
<p>次にユーザから送られてくるリクエスト判定を行います。event.typeによって友達追加かメッセージかを判定します。</p><pre class="crayon-plain-tag">// チャンネルアクセストークンを設定
var channel_access_token = "先ほど発行したチャンネルアクセストークン";

// ユーザからのリクエスト判定(友達追加またはメッセージ)
function doPost(e) {
  var events = JSON.parse(e.postData.contents).events;
  events.forEach(function(event) {
    if (event.type == "message") {
      sendMessage(event);
    }
    if (event.type == "follow") {
      sendFollowMessage(event);
    }
  });
}</pre><p></p>
<h3>友達追加時の挙動</h3>
<p>ユーザから友達追加された際に返すメッセージを設定します。setFollowMessageで友達追加時のメッセージ用意し、ユーザに返します。</p><pre class="crayon-plain-tag">function sendFollowMessage(e) {
  var followMessage = setFollowMessage(e);
  var postData = {
    "replyToken": e.replyToken,
    "messages": followMessage
  };
  var options = {
    "method": "post",
    "headers": {
      "Content-Type": "application/json",
      "Authorization": "Bearer " + channel_access_token
    },
    "payload": JSON.stringify(postData)
  };
  UrlFetchApp.fetch("https://api.line.me/v2/bot/message/reply", options);
}

// 友達追加された際に返すメッセージ
function setFollowMessage(e) {
  var message = [{
    "type": "text",
    "text": "友達追加ありがとうございます！"
  }];
  return (message)
}</pre><p></p>
<h3>メッセージが送られてきた際の挙動</h3>
<p>友達追加時と同様にsetMessageに送られてきたメッセージに対応する返信を用意します。</p>
<p>switch文でそれぞれのメッセージに対応する返信を書いていきます。これがユーザとの応答形式Botの中身になります。LINE謎の場合は答えやヒントなどに対応する返信を書いていくことになります。</p>
<p>defaultは想定していないメッセージが送られてきた場合の返信を書きます。</p><pre class="crayon-plain-tag">function sendMessage(e) {
  var message = setMessage(e);
  var postData = {
    "replyToken": e.replyToken,
    "messages": message
  };
  var options = {
    "method": "post",
    "headers": {
      "Content-Type": "application/json",
      "Authorization": "Bearer " + channel_access_token
    },
    "payload": JSON.stringify(postData)
  };
  UrlFetchApp.fetch("https://api.line.me/v2/bot/message/reply", options);
}

// メッセージが送られてきた際に返す返信の条件分岐
function setMessage(e) {
  switch (e.message.text) {
    case "答え":
      var message = [
        {
          "type": "text",
          "text": "正解です。"
        }
      ];
      return(message)
      break;

  case "ヒント":
    var message = [
      {
        "type": "text",
        "text": "ヒントは〇〇です。"
      }
    ];
    return(message)
    break;

  default:
    var message = [
      {
        "type": "text",
        "text": "ヒントが欲しい場合は「ヒント」と入力してください。"
      }
    ];
    return(message)
    break;
  }
}</pre><p>以上で応答形式Botの完成です。完成後は、「公開」→「ウェブアプリケーションとして導入」を選択し、バージョンを「new」にして再度デプロイしましょう。すると反映されていることが確認できると思います。</p>
<h2>返信メッセージをリッチにしたい</h2>
<p>返信メッセージをもっとリッチにしたい場合は、先ほどインストールしたLINE Bot Designerを使ってみましょう。</p>
<p>インストールが完了後、プロジェクトを作成を選択します。</p>
<p><img data-attachment-id="1463" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-07-18-51-56/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/3c0249882968b20b5e95da4e7c6bd385.png?fit=912%2C992&amp;ssl=1" data-orig-size="912,992" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-07 18.51.56" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/3c0249882968b20b5e95da4e7c6bd385.png?fit=276%2C300&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/3c0249882968b20b5e95da4e7c6bd385.png?fit=800%2C870&amp;ssl=1" loading="lazy" class="aligncenter size-full wp-image-1463" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/3c0249882968b20b5e95da4e7c6bd385.png?resize=800%2C870&#038;ssl=1" alt="" width="800" height="870" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/3c0249882968b20b5e95da4e7c6bd385.png?w=912&amp;ssl=1 912w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/3c0249882968b20b5e95da4e7c6bd385.png?resize=276%2C300&amp;ssl=1 276w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/3c0249882968b20b5e95da4e7c6bd385.png?resize=768%2C835&amp;ssl=1 768w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<p>&nbsp;</p>
<p>プロジェクトの設定を行います。</p>
<p><img data-attachment-id="1461" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-07-18-51-01/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/6b487b7d8cd9331428a53cebba1d025e.png?fit=2692%2C1748&amp;ssl=1" data-orig-size="2692,1748" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-07 18.51.01" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/6b487b7d8cd9331428a53cebba1d025e.png?fit=300%2C195&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/6b487b7d8cd9331428a53cebba1d025e.png?fit=800%2C520&amp;ssl=1" loading="lazy" class="aligncenter size-large wp-image-1461" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/6b487b7d8cd9331428a53cebba1d025e.png?resize=800%2C520&#038;ssl=1" alt="" width="800" height="520" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/6b487b7d8cd9331428a53cebba1d025e.png?resize=1024%2C665&amp;ssl=1 1024w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/6b487b7d8cd9331428a53cebba1d025e.png?resize=300%2C195&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/6b487b7d8cd9331428a53cebba1d025e.png?resize=768%2C499&amp;ssl=1 768w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/6b487b7d8cd9331428a53cebba1d025e.png?resize=1536%2C997&amp;ssl=1 1536w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/6b487b7d8cd9331428a53cebba1d025e.png?resize=2048%2C1330&amp;ssl=1 2048w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/6b487b7d8cd9331428a53cebba1d025e.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/6b487b7d8cd9331428a53cebba1d025e.png?w=2400&amp;ssl=1 2400w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<p>&nbsp;</p>
<p>設定完了後、プロトタイプをGUIで作成することができます。プロトタイプ完成後、右下のJSONをコピーすることで、そのまま使用することができます。</p>
<p><img data-attachment-id="1462" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-07-18-51-35/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/dbbc6d9a4b9aed8697156d8840e8b0ad.png?fit=2672%2C1722&amp;ssl=1" data-orig-size="2672,1722" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-07 18.51.35" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/dbbc6d9a4b9aed8697156d8840e8b0ad.png?fit=300%2C193&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/dbbc6d9a4b9aed8697156d8840e8b0ad.png?fit=800%2C516&amp;ssl=1" loading="lazy" class="aligncenter size-large wp-image-1462" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/dbbc6d9a4b9aed8697156d8840e8b0ad.png?resize=800%2C516&#038;ssl=1" alt="" width="800" height="516" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/dbbc6d9a4b9aed8697156d8840e8b0ad.png?resize=1024%2C660&amp;ssl=1 1024w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/dbbc6d9a4b9aed8697156d8840e8b0ad.png?resize=300%2C193&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/dbbc6d9a4b9aed8697156d8840e8b0ad.png?resize=768%2C495&amp;ssl=1 768w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/dbbc6d9a4b9aed8697156d8840e8b0ad.png?resize=1536%2C990&amp;ssl=1 1536w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/dbbc6d9a4b9aed8697156d8840e8b0ad.png?resize=2048%2C1320&amp;ssl=1 2048w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/dbbc6d9a4b9aed8697156d8840e8b0ad.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/dbbc6d9a4b9aed8697156d8840e8b0ad.png?w=2400&amp;ssl=1 2400w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<p>&nbsp;</p>
<p>ここで画像・動画、テンプレートメッセージなどを設計し、JSONコードをそのままGASにコピペで使うことができます。LINE謎を作成する場合は画像などを使うと思いますので、こちらを積極的に活用してみましょう。</p>
<p><img data-attachment-id="1472" data-permalink="https://mintaku-blog.net/line-mystery/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2020-05-08-11-37-52/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/73b9131f2040382e3d5339634098fc2f.png?fit=2686%2C1736&amp;ssl=1" data-orig-size="2686,1736" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="スクリーンショット 2020-05-08 11.37.52" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/73b9131f2040382e3d5339634098fc2f.png?fit=300%2C194&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/73b9131f2040382e3d5339634098fc2f.png?fit=800%2C517&amp;ssl=1" loading="lazy" class="aligncenter size-large wp-image-1472" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/73b9131f2040382e3d5339634098fc2f.png?resize=800%2C517&#038;ssl=1" alt="" width="800" height="517" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/73b9131f2040382e3d5339634098fc2f.png?resize=1024%2C662&amp;ssl=1 1024w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/73b9131f2040382e3d5339634098fc2f.png?resize=300%2C194&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/73b9131f2040382e3d5339634098fc2f.png?resize=768%2C496&amp;ssl=1 768w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/73b9131f2040382e3d5339634098fc2f.png?resize=1536%2C993&amp;ssl=1 1536w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/73b9131f2040382e3d5339634098fc2f.png?resize=2048%2C1324&amp;ssl=1 2048w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/73b9131f2040382e3d5339634098fc2f.png?w=1600&amp;ssl=1 1600w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/73b9131f2040382e3d5339634098fc2f.png?w=2400&amp;ssl=1 2400w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<h2>実際にLINE謎を作ってみた</h2>
<p><img data-attachment-id="1486" data-permalink="https://mintaku-blog.net/line-mystery/m-1/" data-orig-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/M-1.png?fit=1024%2C512&amp;ssl=1" data-orig-size="1024,512" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="M (1)" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/M-1.png?fit=300%2C150&amp;ssl=1" data-large-file="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/M-1.png?fit=800%2C400&amp;ssl=1" loading="lazy" class="aligncenter size-full wp-image-1486" src="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/M-1.png?resize=800%2C400&#038;ssl=1" alt="" width="800" height="400" srcset="https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/M-1.png?w=1024&amp;ssl=1 1024w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/M-1.png?resize=300%2C150&amp;ssl=1 300w, https://i0.wp.com/mintaku-blog.net/mintaku/wp-content/uploads/2020/05/M-1.png?resize=768%2C384&amp;ssl=1 768w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></p>
<p>実際にLINE謎を作ってみました。ざっくりストーリーから考え、次にストーリーにあわせた謎を作り、開発という流れで行いました。こういう謎解きを作るのは初めてでしたが、丸一日かけて公開まで漕ぎ着けることができました。</p>
<p>初心者向けのLINE謎で10分くらいで解けるので、もし時間があればやっていただけると嬉しいです。</p>
<p>地球最後の日に残された謎：<a href="https://lin.ee/tV2tCPuy" target="_blank" rel="noopener noreferrer">https://lin.ee/tV2tCPuy</a></p>The post <a href="https://mintaku-blog.net/line-mystery/">【LINE謎】LINEで遊べる謎解きの作り方と開発方法まとめ</a> first appeared on <a href="https://mintaku-blog.net">みんたく</a>.]]></content:encoded>
					
					<wfw:commentRss>https://mintaku-blog.net/line-mystery/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1457</post-id>	</item>
		<item>
		<title>jQueryでプルダウンが選択された時にもう一方のプルダウンの中身を決定する方法【Ajax】</title>
		<link>https://mintaku-blog.net/jquery-pulldown/</link>
					<comments>https://mintaku-blog.net/jquery-pulldown/#respond</comments>
		
		<dc:creator><![CDATA[みんたく]]></dc:creator>
		<pubDate>Fri, 12 Apr 2019 14:10:12 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://mintaku-blog.net/?p=908</guid>

					<description><![CDATA[<p>jQueryとAjaxを使ってプルダウンが選択された時にもう一方のプルダウンの中身を決定する方法を紹介します。 フレームワークはRuby on Railsを …</p>
The post <a href="https://mintaku-blog.net/jquery-pulldown/">jQueryでプルダウンが選択された時にもう一方のプルダウンの中身を決定する方法【Ajax】</a> first appeared on <a href="https://mintaku-blog.net">みんたく</a>.]]></description>
										<content:encoded><![CDATA[<p>jQueryとAjaxを使ってプルダウンが選択された時にもう一方のプルダウンの中身を決定する方法を紹介します。</p>
<p>フレームワークはRuby on Railsを使用しています。例として会社・子会社の場合で紹介しています。</p>
<h2>jQueryでプルダウンが選択された時にもう一方のプルダウンの中身を決定する方法</h2>
<p>会社プルダウンと子会社プルダウンを表示しています。子会社プルダウンは会社プルダウンが選択されるまでは非活性にしています。</p>
<p>・_company_index.html.erb</p><pre class="crayon-plain-tag">...

&lt;label&gt;
    &lt;legend&gt;会社&lt;/legend&gt;
    &lt;div&gt;
        &lt;%= create_company_pulldown :company_id, 'company_id', '選択してください', @filter_params[:company_id] %&gt;
    &lt;/div&gt;
&lt;/label&gt;

&lt;label&gt;
    &lt;legend&gt;子会社&lt;/legend&gt;
    &lt;div&gt;
        &lt;%= f.select :subsidiary_company_id, @subsidiary_company_options, { prompt: '選択してください' }, class: 'subsidiary_company_check', disabled: @filter_params[:subsidiary_company_id] == nil %&gt;
    &lt;/div&gt;
&lt;/label&gt;

...</pre><p>&nbsp;</p>
<p>子会社以外の会社を取得し、会社プルダウンに格納</p>
<p>・application_helper.rb</p><pre class="crayon-plain-tag"># 会社マスタプルダウン用
def create_company_pulldown(name, class_name, prompt, selected_id = '')
    companies = ::Company.where(parent_company_id: nil).is_not_old
    select object, name, options_for_select(companies.collect { |u| [u.company_name, u.id] }, selected: selected), options, html_options
end
</pre><p>CoffeScriptで書かれているため若干書き方が異なります。</p>
<p>以下のサイトからjsファイルのjQueryに変換できます。</p>

<div class="ys-blog-card">
	<div class="ys-blog-card__container">
					<figure class="ys-blog-card__image">
				<img src="https://js2coffee.com/favicon.svg" alt="">			</figure>
				<div class="ys-blog-card__text">
			<p class="ys-blog-card__title">
				<a class="ys-blog-card__link" href="http://js2.coffee/">js2coffee - JavaScript Parser &amp; AST Analyzer</a>
			</p>
							<div class="ys-blog-card__dscr">
					Parse JavaScript code into AST (Abstract&hellip;				</div>
										<div class="ys-blog-card__domain">js2.coffee</div>
					</div>
	</div>
</div>

<p>&nbsp;</p>
<p>・companies.coffee</p><pre class="crayon-plain-tag">$ ($) -&gt;
    # 会社プルダウンが変更された時のイベント
    $('#company_id').on 'change', -&gt;
    $subsidiary_company_check = $('.subsidiary_company_check')
    company_id = $('[name=company_id]').val()

    # 会社が選択されていない場合
    if (! company_id)
        $subsidiary_company_check.find('option').remove()
        $subsidiary_company_check.prop('disabled', true)

        return

    # Ajaxで送るデータ整形
    formData = new FormData()
    formData.append 'company_id', company_id

    $.ajax
        type: 'POST'
        url: self.search_subsidiary_company_url
        data: formData
        cache: false
        contentType: false
        processData: false

    # 成功
    .done (data, textStatus, jqXHR) -&gt;
        $subsidiary_company_check.find('option').remove()
        $subsidiary_company_check.prop('disabled', false)
        $subsidiary_company_check.append $('&lt;option&gt;&lt;/option&gt;').text('選択してください').val('parent')
        $subsidiary_company_check.append $('&lt;option&gt;&lt;/option&gt;').text('すべて').val('all')

        # 子会社が存在しない場合
        if (data['companies'].length == 0)
            $subsidiary_company_check.prop('disabled', true)
            $group_company_check.prop('checked', false)
            $group_company_check.prop('disabled', true)

        # 子会社が存在する場合
        else
            $group_company_check.prop('disabled', false)

        # 子会社プルダウンにDOM生成
        $(data['companies']).each (i) -&gt;
            $subsidiary_company_check.append $('&lt;option&gt;&lt;/option&gt;').val(data['companies'][i].id).text(data['companies'][i].company_name)
            return

        # 失敗
        .fail (jqXHR, textStatus, errorThrown) -&gt;

        #エラーメッセージ表示
        $('.error_message').html('')
        for k, v of $.parseJSON(jqXHR.responseText)
            $('.error_xs').append('&lt;p&gt;' + v[0]["message"] + '&lt;/p&gt;')
            return</pre><p>&nbsp;</p>
<p>ルーティング設定<br />
routes.rb</p><pre class="crayon-plain-tag">...

post :search_subsidiary_company

...
</pre><p>&nbsp;</p>
<p>AjaxのURL先。選択した会社IDから子会社取得を取得しています。</p>
<p>companies_controller.rb</p><pre class="crayon-plain-tag">def search_subsidiary_company
    begin
        company_id = params[:company_id]
        @companies = Company.where(parent_company_id: company_id)
        respond_to do |format|
            format.json {
                render json: {companies: @companies}, status: 200
            }
        end
    rescue ActiveRecord::ActiveRecordError =&gt; e
        format.json {
            render json: e.message, status: :unprocessable_entity
        }
    end
end
</pre><p></p>The post <a href="https://mintaku-blog.net/jquery-pulldown/">jQueryでプルダウンが選択された時にもう一方のプルダウンの中身を決定する方法【Ajax】</a> first appeared on <a href="https://mintaku-blog.net">みんたく</a>.]]></content:encoded>
					
					<wfw:commentRss>https://mintaku-blog.net/jquery-pulldown/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">908</post-id>	</item>
		<item>
		<title>【JavaScript】onclickで「return false」が効かない時の対処法</title>
		<link>https://mintaku-blog.net/javascript-onclick/</link>
					<comments>https://mintaku-blog.net/javascript-onclick/#respond</comments>
		
		<dc:creator><![CDATA[みんたく]]></dc:creator>
		<pubDate>Mon, 23 Apr 2018 11:39:42 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://mintaku-blog.net/?p=260</guid>

					<description><![CDATA[<p>JavaScriptをいじっててハマったのでメモ。 &#38;nbsp; onclickで「return false」が効かない時の対処法 function …</p>
The post <a href="https://mintaku-blog.net/javascript-onclick/">【JavaScript】onclickで「return false」が効かない時の対処法</a> first appeared on <a href="https://mintaku-blog.net">みんたく</a>.]]></description>
										<content:encoded><![CDATA[<p>JavaScriptをいじっててハマったのでメモ。</p>
<p>&nbsp;</p>
<h2>onclickで「return false」が効かない時の対処法</h2>
<p></p><pre class="crayon-plain-tag">function myCheck() {
    var j = 0;
    for (var i = 0; i &lt; document.form1.elements.length - 1; i++) {
        if (document.form1.elements[i].checked) {
            j++;
        }
    }

    if (j &lt; 2) {
        alert("項目が選択されていません。");
        return false;
    } else {
        return true;
    }
}</pre><p>jsの部分です。想定では、ダイアログが表示された時は、データをサーバに送らず処理をキャンセルするイメージでしたが、なぜかうまくいかん&#8230;。</p>
<p>&nbsp;</p><pre class="crayon-plain-tag">&lt;button type="submit" onclick="myCheck();" value="送信"&gt;&lt;/button&gt;</pre><p>対処法は「onclick」のとこを修正します。下のように「return myCheck();」に直したらいけました。</p><pre class="crayon-plain-tag">&lt;button type="submit" onclick="return myCheck();" value="送信"&gt;&lt;/button&gt;</pre><p>どうやら&lt;script&gt;内に「return false」を書いても、イベントハンドラはfalseを認識しないようです。</p>
<p>そのため、イベントハンドラにreturnを明記することで解決できますよ！</p>The post <a href="https://mintaku-blog.net/javascript-onclick/">【JavaScript】onclickで「return false」が効かない時の対処法</a> first appeared on <a href="https://mintaku-blog.net">みんたく</a>.]]></content:encoded>
					
					<wfw:commentRss>https://mintaku-blog.net/javascript-onclick/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">260</post-id>	</item>
		<item>
		<title>node.jsで「internal/modules/cjs/loader.js:550」のエラーが出た時の対処法</title>
		<link>https://mintaku-blog.net/nodejs-550/</link>
					<comments>https://mintaku-blog.net/nodejs-550/#respond</comments>
		
		<dc:creator><![CDATA[みんたく]]></dc:creator>
		<pubDate>Sat, 07 Apr 2018 15:08:11 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://mintaku-blog.net/?p=161</guid>

					<description><![CDATA[<p>備忘録として、残しておきます。 同じエラーが出た方は参考にしてみてください。 &#38;nbsp; 「internal/modules/cjs/loader …</p>
The post <a href="https://mintaku-blog.net/nodejs-550/">node.jsで「internal/modules/cjs/loader.js:550」のエラーが出た時の対処法</a> first appeared on <a href="https://mintaku-blog.net">みんたく</a>.]]></description>
										<content:encoded><![CDATA[<p>備忘録として、残しておきます。</p>
<p>同じエラーが出た方は参考にしてみてください。</p>
<p>&nbsp;</p>
<h2>「internal/modules/cjs/loader.js:550」のエラーが出た時の対処法</h2>
<p></p><pre class="crayon-plain-tag">internal/modules/cjs/loader.js:550
 throw err;
 ^

Error: Cannot find module 'nightmare'
 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
 at Function.Module._load (internal/modules/cjs/loader.js:475:25)
 at Module.require (internal/modules/cjs/loader.js:598:17)
 at require (internal/modules/cjs/helpers.js:11:18)
 at Object.&lt;anonymous&gt; (/Users/simanapo/Desktop/yahooSearch.js:1:81)
 at Module._compile (internal/modules/cjs/loader.js:654:30)
 at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
 at Module.load (internal/modules/cjs/loader.js:566:32)
 at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
 at Function.Module._load (internal/modules/cjs/loader.js:498:3)&lt;br&gt;</pre><p>こんなエラーが出ていませんか？モジュールが足りないよって怒られています。</p>
<p>なので足りないモジュールをインストールして、ローカルにリンクしましょう。</p>
<p>以下のコマンドを試してみてください。</p><pre class="crayon-plain-tag">npm install -g nightmare
npm link nightmare&lt;br&gt;</pre><p>nightmareのとこは「Error: Cannot find module」で表示されたモジュールに置き換えてください。</p>
<p>どうでしょう？解決しましたか？</p>The post <a href="https://mintaku-blog.net/nodejs-550/">node.jsで「internal/modules/cjs/loader.js:550」のエラーが出た時の対処法</a> first appeared on <a href="https://mintaku-blog.net">みんたく</a>.]]></content:encoded>
					
					<wfw:commentRss>https://mintaku-blog.net/nodejs-550/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">161</post-id>	</item>
	</channel>
</rss>
