tag:blogger.com,1999:blog-73174330072379405352024-02-21T16:44:26.177+08:00Wの亂入開發之道每個人都很單純,大家都是夥伴。Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.comBlogger303125tag:blogger.com,1999:blog-7317433007237940535.post-55406684104924812852018-12-30T21:49:00.000+08:002018-12-30T22:13:20.391+08:00k8s mongo statefultype :LoadBalancer 可連外,但無法使用 cvallance/mongo-k8s-sidecar
<script src="https://gist.github.com/Wolke/4b4e258e55b78b69fd37150a48ce57d1.js"></script>
cvallance/mongo-k8s-sidecar
<script src="https://gist.github.com/Wolke/14e15a52f5bc972b2231596d181c9e28.js"></script><div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-65484187024522510952018-12-20T13:16:00.001+08:002018-12-20T13:16:10.704+08:00解 下載檔預設是gz<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;">
<div>
<br /></div>
<div>
<span style="color: #569cd6;">const</span> <span style="color: #9cdcfe;">request</span> = <span style="color: #dcdcaa;">require</span>(<span style="color: #ce9178;">'request'</span>);</div>
<div>
<span style="color: #569cd6;">const</span> <span style="color: #9cdcfe;">zlib</span> = <span style="color: #dcdcaa;">require</span>(<span style="color: #ce9178;">'zlib'</span>);</div>
<div>
<span style="color: #569cd6;">const</span> <span style="color: #9cdcfe;">concat</span> = <span style="color: #dcdcaa;">require</span>(<span style="color: #ce9178;">'concat-stream'</span>);</div>
<br /><div>
<span style="color: #569cd6;">const</span> <span style="color: #dcdcaa;">check_place_list</span> = () <span style="color: #569cd6;">=></span> {</div>
<div>
<span style="color: #c586c0;">return</span> <span style="color: #569cd6;">new</span> <span style="color: #4ec9b0;">Promise</span>(<span style="color: #569cd6;">async</span> (<span style="color: #9cdcfe;">resolve</span>, <span style="color: #9cdcfe;">reject</span>) <span style="color: #569cd6;">=></span> {</div>
<div>
<span style="color: #dcdcaa;">request</span>(<span style="color: #ce9178;">"https://tcgbusfs.blob.core.windows.net/blobtcmsv/TCMSV_allavailable.gz"</span>)</div>
<div>
.<span style="color: #dcdcaa;">pipe</span>(<span style="color: #9cdcfe;">zlib</span>.<span style="color: #dcdcaa;">createGunzip</span>())</div>
<div>
.<span style="color: #dcdcaa;">pipe</span>(<span style="color: #dcdcaa;">concat</span>((<span style="color: #9cdcfe;">stringBuffer</span>: <span style="color: #4ec9b0;">any</span>) <span style="color: #569cd6;">=></span> {</div>
<div>
<span style="color: #6a9955;">// console.log(stringBuffer.toString());</span></div>
<br /><div>
}));</div>
<div>
</div>
<div>
})</div>
<div>
}</div>
</div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-73039325522231540102018-12-17T14:12:00.002+08:002019-01-01T10:03:52.852+08:00k8s 小工具kubectl run -i --tty alpine --image=alpine --restart=Never -- sh<br />
kubectl exec -ti alpine /bin/sh<br />
apk add --no-cache curl<br />
<br />
外部curl<br />
kubectl run example -i -t --rm --restart=Never --image centos:7 -- curl -s http://ipinfo.io/ip
<br />
<br />
<br />
開mongo image<br />
<pre class="graf graf--pre graf-after--p" id="9300" name="9300" style="background: rgba(0, 0, 0, 0.05); color: rgba(0, 0, 0, 0.84); font-family: Menlo, Monaco, "Courier New", Courier, monospace; font-size: 16px; margin-top: 43px; overflow: auto; padding: 20px; white-space: pre-wrap;"><code class="markup--code markup--pre-code" style="font-family: inherit; font-size: 1em;">kubectl run -it --rm --restart=Never mongo-cli --image=mongo --command -- /bin/bash
root@mongo-cli:/# mongo "mongodb://mongo-0.mongo.db,mongo-1.mongo.db,mongo-2.mongo.db:27017/test"</code></pre>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-74777412068782147512018-11-12T17:18:00.004+08:002018-11-12T17:18:43.706+08:00gke k8s 筆記https://cloud.google.com/sdk/gcloud/reference/config/set<br />
設定 porject 跟 zone 才能抓到 叢集<br />
<span style="color: #212121; font-family: Roboto, sans-serif; font-size: 16px;">To set the project </span><code style="background: rgb(247, 247, 247); box-sizing: inherit; color: #37474f; font-family: "Roboto Mono", monospace; font-size: 14.4px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 1; margin-top: 0px; padding: 1px 4px; word-break: break-word;">property</code><span style="color: #212121; font-family: Roboto, sans-serif; font-size: 16px;"> in the core section, run:</span><br />
<pre style="background: rgb(33, 33, 33); box-sizing: inherit; color: #eceff1; font-family: "Roboto Mono", monospace; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 20px; margin-bottom: 16px; margin-top: 16px; overflow: auto; padding: 8px; position: relative;"><div class="devsite-code-button-wrapper" style="box-sizing: inherit; margin: -8px 0px 0px; padding: 0px; position: absolute; right: 0px;">
<div aria-label="Dark code theme" class="devsite-code-button gc-analytics-event material-icons devsite-dark-code-button" data-category="Site-Wide Custom Events" data-label="Dark Code Toggle" data-title="Dark code theme" data-tooltip-align="b,c" data-tooltip="Light code theme" style="-webkit-font-smoothing: antialiased; background: rgba(204, 204, 204, 0.15); box-sizing: inherit; color: white; cursor: default; direction: ltr; display: inline-block; font-family: "Material Icons"; font-feature-settings: "liga"; font-size: 18px; line-height: 1; margin: 0px; overflow-wrap: normal; padding: 3px; transition: background 0.2s ease 0s; vertical-align: bottom; white-space: nowrap;" track-name="darkCodeToggle" track-type="exampleCode">
</div>
</div>
$ <a href="https://cloud.google.com/sdk/gcloud/reference/config/set" style="box-sizing: inherit; color: #1a73e8; outline: 0px; text-decoration-line: none;">gcloud config set</a> project myProject
</pre>
<div style="box-sizing: inherit; color: #212121; font-family: Roboto, sans-serif; font-size: 16px; margin-bottom: 16px; margin-top: 16px; padding: 0px;">
To set the <code style="background: rgb(247, 247, 247); box-sizing: inherit; color: #37474f; font-family: "Roboto Mono", monospace; font-size: 14.4px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 1; padding: 1px 4px; word-break: break-word;">zone</code> property in the <code style="background: rgb(247, 247, 247); box-sizing: inherit; color: #37474f; font-family: "Roboto Mono", monospace; font-size: 14.4px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 1; padding: 1px 4px; word-break: break-word;">compute</code> section, run:</div>
<pre style="background: rgb(33, 33, 33); box-sizing: inherit; color: #eceff1; font-family: "Roboto Mono", monospace; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 20px; margin-bottom: 16px; margin-top: 16px; overflow: auto; padding: 8px; position: relative;"><div class="devsite-code-button-wrapper" style="box-sizing: inherit; margin: -8px 0px 0px; padding: 0px; position: absolute; right: 0px;">
<div aria-label="Dark code theme" class="devsite-code-button gc-analytics-event material-icons devsite-dark-code-button" data-category="Site-Wide Custom Events" data-label="Dark Code Toggle" data-title="Dark code theme" data-tooltip-align="b,c" data-tooltip="Light code theme" style="-webkit-font-smoothing: antialiased; background: rgba(204, 204, 204, 0.15); box-sizing: inherit; color: white; cursor: default; direction: ltr; display: inline-block; font-family: "Material Icons"; font-feature-settings: "liga"; font-size: 18px; line-height: 1; margin: 0px; overflow-wrap: normal; padding: 3px; transition: background 0.2s ease 0s; vertical-align: bottom; white-space: nowrap;" track-name="darkCodeToggle" track-type="exampleCode">
</div>
</div>
$ <a href="https://cloud.google.com/sdk/gcloud/reference/config/set" style="box-sizing: inherit; color: #1a73e8; outline: 0px; text-decoration-line: none;">gcloud config set</a> compute/zone asia-east1-b
</pre>
<div style="box-sizing: inherit; color: #212121; font-family: Roboto, sans-serif; font-size: 16px; margin-bottom: 16px; margin-top: 16px; padding: 0px;">
<br /></div>
<div style="box-sizing: inherit; color: #212121; font-family: Roboto, sans-serif; font-size: 16px; margin-bottom: 16px; margin-top: 16px; padding: 0px;">
<br /></div>
<div style="box-sizing: inherit; color: #212121; font-family: Roboto, sans-serif; font-size: 16px; margin-bottom: 16px; margin-top: 16px; padding: 0px;">
<br /></div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-44739479493863955792018-09-21T11:21:00.003+08:002018-09-22T15:38:19.583+08:00Voice App 2018展望smart speaker今夾應該是起點,<br />
其實大家都是猜。<br />
<br />
市面上smart speaker 百花齊放的,<br />
最終比的還是 語音的辨識率,<br />
而語音辨識率最終還是得來自語音辨識資料的大數據,<br />
在這一點上,<br />
我實在是不知道,<br />
其他家要怎麼跟,<br />
android(Google) iphone(mac)比,<br />
而homepod(mac)的定價也實在是...<br />
<br />
<br />
Google assistant 自已內部的sdk 居然就有兩版 <span style="background-color: white; color: #616161; font-family: "roboto" , "helvetica" , sans-serif; font-size: 16px;"> </span><a href="https://github.com/actions-on-google/actions-on-google-nodejs/tree/v2.0.0-alpha" style="-webkit-tap-highlight-color: rgba(255, 255, 255, 0); background-color: white; color: #ffab40; font-family: Roboto, Helvetica, sans-serif; font-size: 16px;">Actions on Google v2 Alpha</a><span style="background-color: white; color: #616161; font-family: "roboto" , "helvetica" , sans-serif; font-size: 16px;"> and </span><a href="https://github.com/dialogflow/dialogflow-fulfillment-nodejs" style="-webkit-tap-highlight-color: rgba(255, 255, 255, 0); background-color: white; color: #ffab40; font-family: Roboto, Helvetica, sans-serif; font-size: 16px;">Dialogflow Fulfillment Beta</a><span style="background-color: white; color: #616161; font-family: "roboto" , "helvetica" , sans-serif; font-size: 16px;"> </span>好傻眼。<br />
<a href="https://matthewayne.com/post/actions-on-google-v2-alpha-dialogflow-fullfillment-beta/">https://matthewayne.com/post/actions-on-google-v2-alpha-dialogflow-fullfillment-beta/</a><br />
不過跟據diagflow的coder所撰寫的本文表示,<br />
用dialogflow就對了,因為dialogflow會支援google assistant完整之外,還可以支援一堆平台,<br />
<br />
雖然發現本篇是我在看actions on google之後,再度傻眼。<br />
不過作者有清楚表達 actions on google 這個sdk之所以持續存在,主要是這個sdk 才是對google assistant 支援最完整的。<br />
<br />
因為目前smart speaker 百花齊放的,<br />
1.以未來性google home比較有機會<br />
2.對平台有最大限度的支援<br />
所以目前還是選dialogflow的sdk比較穩妥<br />
<br />
但當 google home 打下江山之後,完整支援的actions on google會是好的選擇<br />
<br />
不過當我看完 dialogflow 怎麼取 permission 時,我又變心了,因為它目前是用 http request 來取,也太麻煩了。<br />
<br />
結論:<br />
如果webhock要支不同的平台,例如 google assistant ; aws alxea ; line clova 等,<br />
firebase cloud function 還是得依照不同平台來做設計,才會有完整的體驗。<br />
例如 google home 就用 actions-on-google 其他的用 diagflow-fullfillment<br />
<br />
<br /><div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-948485390475920552018-06-01T00:58:00.000+08:002018-06-01T00:58:20.839+08:00google cloud storage + google Load balancing + google cloud dns + google cloud cdn + Letsencrypt free ssl cert前言:<br />
因為我的AWS到期了,我很多站要搬家,我的GCP 有credits 還沒用完,故決定搬到 GCP<br />
<br />
問題點:<br />
firebase hosting 有送 ssl ,網頁直接丟 public 就搞定了,原本是最理想的方案,結果,他一個專案只能有一個 public;而一個billing account 只能連 5 個 project,而我有很多站...]<br />
<br />
解決方案:<br />
1.function 的部份直接用 google cloud function 或 firebase function 處理<br />
<br />
2.靜態網頁的部分,<br />
google cloud storage 的bucket 可以直接在 dns 設定裡加 cname => www / c.storage.googleapis.com => bucket: http://storage.googleapis.com/www.example.com/<br />
就直接對應上去了。<br />
<a href="https://jerrynest.io/cloud-storage-static-web/">https://jerrynest.io/cloud-storage-static-web/</a><br />
<br />
but<br />
https<br />
就得靠<br />
google Load balancing + google cloud dns + google cloud cdn<br />
解<br />
<a href="https://console.cloud.google.com/net-services/loadbalancing/">https://console.cloud.google.com/net-services/loadbalancing/</a><br />
<br />
先去申請一個免費的ssl<br />
<a href="https://www.sslforfree.com/">https://www.sslforfree.com/</a><br />
<a href="https://cloud.google.com/compute/docs/load-balancing/tcp-ssl/">https://cloud.google.com/compute/docs/load-balancing/tcp-ssl/</a><br />
直接申請https那個就好了。<br />
<div>
<br /></div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-43668657419809963222018-05-18T13:41:00.000+08:002018-05-18T13:41:45.812+08:00web push 完整教學https://thihara.github.io/Web-Push/<br />
<br /><div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-42889110051357447522018-05-16T13:57:00.005+08:002018-05-16T13:57:42.034+08:00web (push api)原理跟範例:<br />
<a href="https://developers.google.com/web/ilt/pwa/introduction-to-push-notifications">https://developers.google.com/web/ilt/pwa/introduction-to-push-notifications</a><br />
<br /><div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-64911671028182624652018-03-22T22:42:00.005+08:002018-03-22T22:42:59.567+08:00aws lambda 只有isomorphic-fetch傳上去可以正常跑出來<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;">
<div>
<span style="color: #ce9178;">'use strict'</span>;</div>
<br /><div>
<span style="color: #569cd6;">const</span><span style="color: #9cdcfe;"> fetch</span> = <span style="color: #dcdcaa;">require</span>(<span style="color: #ce9178;">'isomorphic-fetch'</span>);</div>
<br /><br /><div>
module.<span style="color: #4ec9b0;">exports</span>.<span style="color: #dcdcaa;">hello</span> = (<span style="color: #9cdcfe;">event</span>,<span style="color: #9cdcfe;"> context</span>,<span style="color: #9cdcfe;"> callback</span>) <span style="color: #569cd6;">=></span> {</div>
<br /><div>
<span style="color: #dcdcaa;">fetch</span>(<span style="color: #ce9178;">'https://xxxx/graphql'</span>, {</div>
<div>
<span style="color: #ce9178;">method</span>: <span style="color: #ce9178;">'POST'</span>,</div>
<div>
<span style="color: #ce9178;">headers</span>: { <span style="color: #ce9178;">'Content-Type'</span>: <span style="color: #ce9178;">'application/json'</span> },</div>
<div>
<span style="color: #ce9178;">body</span>: <span style="color: #9cdcfe;">JSON</span>.<span style="color: #dcdcaa;">stringify</span>({</div>
<div>
<span style="color: #ce9178;">query</span>:<span style="color: #ce9178;"> `</span></div>
<div>
<span style="color: #ce9178;"> {</span></div>
<div>
<span style="color: #ce9178;"> </span><span style="color: #ce9178;">}</span></div>
<div>
<span style="color: #ce9178;"> `</span> }),</div>
<div>
})</div>
<div>
.<span style="color: #dcdcaa;">then</span>(<span style="color: #9cdcfe;">res</span> <span style="color: #569cd6;">=></span><span style="color: #9cdcfe;"> res</span>.<span style="color: #dcdcaa;">json</span>())</div>
<div>
.<span style="color: #dcdcaa;">then</span>(<span style="color: #9cdcfe;">res</span> <span style="color: #569cd6;">=></span> <span style="color: #4ec9b0;">console</span>.<span style="color: #dcdcaa;">log</span>(<span style="color: #9cdcfe;">res</span>.<span style="color: #9cdcfe;">data</span>));</div>
<div>
<span style="color: #569cd6;"> const</span><span style="color: #9cdcfe;"> response</span> = {</div>
<div>
<span style="color: #ce9178;">statusCode</span>: <span style="color: #b5cea8;">200</span>,</div>
<div>
<span style="color: #ce9178;">body</span>: <span style="color: #9cdcfe;">JSON</span>.<span style="color: #dcdcaa;">stringify</span>({</div>
<div>
<span style="color: #ce9178;">message</span>: <span style="color: #ce9178;">'Go Serverless v1.0! Your function executed successfully!'</span>,</div>
<div>
<span style="color: #ce9178;">input</span>:<span style="color: #9cdcfe;"> event</span>,</div>
<div>
}),</div>
<div>
};</div>
<br /><div>
<span style="color: #dcdcaa;">callback</span>(<span style="color: #569cd6;">null</span>,<span style="color: #9cdcfe;"> response</span>);</div>
<br /><div>
<span style="color: #608b4e;"> // Use this code if you don't use the http event with the LAMBDA-PROXY integration</span></div>
<div>
<span style="color: #608b4e;"> // callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });</span></div>
<div>
};</div>
</div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-41724357916962869412018-03-17T17:57:00.001+08:002018-03-17T17:57:27.323+08:00serverless 開資源只會跑第一次serverless 開資源只會跑第一次<br /><br /><div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-73636445713418193752018-03-16T23:55:00.003+08:002018-03-16T23:55:36.168+08:00chatbot的未來在車用系統現在的chatbot應用平台(line fb messenger telegram slack....),根本無法讓chatb ot作良好的應用。<br />在有眼有手有腳可用的情況之下,<div>
<div>
app 或 pwa 的solution,</div>
<div>
都可以讓任何情況應用的更好,</div>
<div>
其實現有2018.03以前做的都是玩具而已。</div>
<div>
<br /></div>
<div>
什麼情況會沒有眼手腳可用?</div>
<div>
就是開車啊!</div>
<div>
<br /></div>
<div>
所以chatbot的殺手應用,肯定是車用系統。</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Anonymoushttp://www.blogger.com/profile/00458149907390232647noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-72924473482637883252018-02-25T12:33:00.000+08:002018-02-25T23:30:33.488+08:00serverless gcp (google cloud functioin)參考這個。<br />
<div>
開新的 project</div>
<div>
要下載keyjson 註明在 serverless.yaml裡</div>
<div>
<br /></div>
<div>
sls deploy </div>
<div>
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;">
<div>
<span style="color: #569cd6;">service</span>: <span style="color: #ce9178;">serverless-85332</span></div>
<br />
<div>
<span style="color: #569cd6;">provider</span>:</div>
<div>
<span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">google</span></div>
<div>
<span style="color: #569cd6;">runtime</span>: <span style="color: #ce9178;">nodejs</span></div>
<div>
<span style="color: #569cd6;">project</span>: <span style="color: #ce9178;">serverless-85332 //這裡要註意,要和你的project名稱一樣</span></div>
<div>
<span style="color: #608b4e;"># the path to the credentials file needs to be absolute</span></div>
<div>
<span style="color: #569cd6;">credentials</span>: <span style="color: #ce9178;">~/.gcloud/keyfile.json</span></div>
</div>
</div>
<div>
後記:</div>
<div>
bug:</div>
<div>
因為想查 google cloud functions 有沒有台灣,所以下載 gcloud,但是不知道為何,目錄權限得一直自已開啟。</div>
<div>
<br />
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;">
<br /><div>
<span style="color: #569cd6;">functions</span>:</div>
<div>
<span style="color: #569cd6;">line_notify_cpc</span>:</div>
<div>
<span style="color: #569cd6;">handler</span>: <span style="color: #ce9178;">handler.line_notify // handler 的命名,gcp不允許的樣子</span></div>
<div>
<span style="color: #569cd6;">events</span>:</div>
<div>
- <span style="color: #569cd6;">http</span>:</div>
<div>
<span style="color: #569cd6;">method</span>: <span style="color: #ce9178;">get</span></div>
<div>
<span style="color: #569cd6;">path</span>: <span style="color: #ce9178;">line_notify_cpc</span></div>
</div>
</div>
<div>
<br /></div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-10362361465604907572018-02-10T00:47:00.002+08:002018-02-10T00:47:43.221+08:00使用 botframework + botbuilder-linebot-connector + serverless(AWS lambda) + botbuilder-mongodb-storage 連 mongodb cluster 開發 LineBot 入門 2<a href="https://github.com/Wolke/linebot-serverless-MongoDbStorage-LineConnector-typeScript-starter-Kit">https://github.com/Wolke/linebot-serverless-MongoDbStorage-LineConnector-typeScript-starter-Kit</a><br />
<br />
我直接解擇這個架構好了<br />
<br />
<ol>
<li>serverless.yml 這個就serverless 的設定,得配合我開在AWS 上的 mongo cluster ,才能讓 aws lambda 存取。<a href="http://wolke-codes.blogspot.tw/2018/01/serverless-aws-lambda-aws-mongodb.html">http://wolke-codes.blogspot.tw/2018/01/serverless-aws-lambda-aws-mongodb.html</a></li>
<li>bot/bot.ts bot 的流程... 可以參考我在IT鐵人的不負責任教學:<a href="https://ithelp.ithome.com.tw/users/20046160/ironman/1510">https://ithelp.ithome.com.tw/users/20046160/ironman/1510</a></li>
<li>handler.js :這個是serverless 的預設的 function 定義的地方。<br /><pre style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-color: rgb(52, 52, 52) !important; box-shadow: none !important; transition: none !important; word-wrap: break-word;"><span style="color: silver; font-family: Menlo, Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="white-space: pre-wrap;">'use strict';
var config = require("./conf");//</span></span><span style="color: black; font-family: Times; white-space: normal;">讀取你的設定</span><span style="color: silver; font-family: Menlo, Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="white-space: pre-wrap;">
var bot_dailog = require("./bot/bot")//</span></span><span style="color: black; font-family: Times; white-space: normal;">將bot 流程 require 進來。</span><span style="color: silver; font-family: Menlo, Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="white-space: pre-wrap;">
var botbuilder_linebot_connector_1 = require("botbuilder-linebot-connector");
var botbuilder_mongodb_storage_1 = require("botbuilder-mongodb-storage");
var builder = require('botbuilder');
var connector = new botbuilder_linebot_connector_1.LineConnector({
hasPushApi: false,
// your line
channelId: process.env.channelId || config.channelId,
channelSecret: process.env.channelSecret || config.channelSecret,
channelAccessToken: process.env.channelAccessToken || config.channelAccessToken
});//</span></span><span style="color: black; font-family: Times; white-space: normal;">產生connector</span><span style="color: silver; font-family: Menlo, Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="white-space: pre-wrap;">
</span></span><pre style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-color: rgb(52, 52, 52) !important; box-shadow: none !important; color: silver; font-family: Menlo, Consolas, "Liberation Mono", Menlo, Courier, monospace !important; transition: none !important; white-space: pre-wrap; word-wrap: break-word;">
</pre>
<span style="font-family: Menlo, Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="white-space: pre-wrap;"><span style="color: silver;">var bot = new builder.UniversalBot(connector) </span>//產生 bot<span style="color: silver;">
.set("storage", new botbuilder_mongodb_storage_1.MongoDbStorage({
DatabaseName: config.DatabaseName,
collectionName: config.collectionName,
mongoIp: config.mongoIp,
mongoPort: config.mongoPort,
// mongoIp: "ds125578.mlab.com",
// mongoPort: "255xx",
// username: config.username,
// password: config.password
}));
bot_dailog.default(bot)</span>//將bot流程套用<span style="color: silver;">
</span></span></span><pre style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-color: rgb(52, 52, 52) !important; box-shadow: none !important; color: silver; font-family: Menlo, Consolas, "Liberation Mono", Menlo, Courier, monospace !important; transition: none !important; white-space: pre-wrap; word-wrap: break-word;">
</pre>
<span style="color: silver; font-family: Menlo, Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="white-space: pre-wrap;">
module.exports.line = (event, context, callback) => {
connector.serverlessWebhock(event) //<span style="color: black; font-family: Times;"><span style="white-space: normal;">記得加 </span></span><span style="color: black;">connector.serverlessWebhock(event) 就可以了。</span><pre style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-color: rgb(52, 52, 52) !important; box-shadow: none !important; color: black; transition: none !important; word-wrap: break-word;"><span style="color: silver; font-family: Menlo, Consolas, Liberation Mono, Menlo, Courier, monospace;"></span></pre>
<span style="color: silver; font-family: Menlo, Consolas, Liberation Mono, Menlo, Courier, monospace;"></span>
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};
callback(null, response);
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });
};
</span></span><pre style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-color: rgb(52, 52, 52) !important; box-shadow: none !important; transition: none !important; word-wrap: break-word;"><span style="font-family: Times;"><span style="white-space: normal;"> </span></span></pre>
<span style="color: silver; font-family: Menlo, Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="white-space: pre-wrap;">
</span></span></pre>
</li>
</ol>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-69351630052610121292018-02-10T00:31:00.000+08:002018-02-10T00:33:43.618+08:00使用 botframework + botbuilder-linebot-connector + serverless(AWS lambda) + botbuilder-mongodb-storage 連 mongodb cluster 開發 LineBot 入門 1名字超長的一篇教學,<br />
<div>
為什麼會搞到這麼長,</div>
<div>
就是經驗而已。</div>
<div>
<br /></div>
<div>
<br />
<ol>
<li>botframework: ms 出的一個開放 chat bot 的一個套件,有官方網站 dev.botframework ,但不幸沒有支援日台泰三國愛用的Line。</li>
<li>botbuilder-linebot-connector : 小弟做的一個connector,連上 botframework的 bulider 不需要 dev.botframework 的官網帳號,就可以來開發bot了。</li>
<li>serverless(AWS lambda) :會選用serverless ,純粹是經驗,因為之前開一個 AWS EC2 micro 的機器,差不多10個使用者,同時在和bot溝通時,就有明顯的delay了,故改用serverless架構,來必免這個scale的問題。</li>
<li>botbuilder-mongodb-storage : 小弟做的一個 mongodb storage for botframework 用的,主要是將 bot state 存在 mongo上使用。</li>
<li>mongodb cluster : 這看你自已的選擇,用 mlab 或是 mongodb altas 或是自已架,都是不錯的選擇。不過請注意 line 有replayToken 會失效的問題,建議不要取存時間過長,導致失效而發不出去。</li>
</ol>
</div>
<div>
我的選擇是直接 serverless (AWS lambda 東京) <complete id="goog_1439641826">+ 開AWS </complete>mongodb cluster (<a href="https://ap-northeast-1.console.aws.amazon.com/ec2/v2/home?region=ap-northeast-1#SecurityGroups:groupId=sg-db38a1a2;sort=groupId">https://ap-northeast-1.console.aws.amazon.com/ec2/v2/home?region=ap-northeast-1#SecurityGroups:groupId=sg-db38a1a2;sort=groupId</a> )東京,因為Line 的 bot 機房就在東京。<br />
<br /></div>
<div>
<br /></div>
<!--?xml version="1.0" encoding="UTF-8"?-->
<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-62600738168840527522018-02-09T00:50:00.003+08:002018-02-09T00:55:44.804+08:00lambda subnet (serverless )設錯 網域 會連不到...<label awsui-form-field-region="label" class="awsui-form-field-label" for="awsui-input-16" style="background-color: white; box-sizing: border-box; display: inline-block; line-height: 2rem;"><span data-reactroot="" style="font-size: 14px;"><span style="color: #545b64; font-family: "amazon ember" , "helvetica neue" , "roboto" , "arial" , sans-serif;">要跟ec2上的一置<br />https://ap-northeast-1.console.aws.amazon.com/lambda/home?region=ap-northeast-1</span></span></label><br />
<label awsui-form-field-region="label" class="awsui-form-field-label" for="awsui-input-16" style="background-color: white; box-sizing: border-box; color: #545b64; display: inline-block; font-family: "Amazon Ember", "Helvetica Neue", Roboto, Arial, sans-serif; font-size: 14px; line-height: 2rem;"><span data-reactroot="">Subnets*</span></label><br />
<div awsui-form-field-region="description" class="awsui-form-field-description" style="background-color: white; color: #879596; font-family: "Amazon Ember", "Helvetica Neue", Roboto, Arial, sans-serif; font-size: 1.2rem; line-height: 1.5rem;">
<span data-reactroot="">Select the VPC Subnets that Lambda should use to set up your VPC configuration. Format: "subnet-id (cidr-block) | az name-tag".</span></div>
<div class="awsui-grid awsui-form-field-controls" style="background-color: white; color: #16191f; font-family: "Amazon Ember", "Helvetica Neue", Roboto, Arial, sans-serif; font-size: 14px; padding-top: 0.5rem;">
<div class="awsui-row" style="box-sizing: border-box; display: flex; flex-wrap: wrap; margin: -1rem;">
<div awsui-form-field-region="control" class="awsui-form-field-control awsui-invalid col-9 col-xxs-12" style="box-sizing: border-box; flex: 0 0 100%; max-width: 100%; min-height: 1px; padding: 1rem; position: relative;">
<span style="box-sizing: border-box;"></span><br />
<div data-reactroot="" style="box-sizing: border-box;">
<span style="box-sizing: border-box;"><awsui-multiselect initialized="true" style="box-sizing: border-box; display: inline-block; font-size: 1.4rem; line-height: 2rem; min-width: 100px; position: relative; width: 362.5px;"></awsui-multiselect></span><br />
<div class="" style="box-sizing: border-box;">
<div class="awsui-select-keyboard-area" style="box-sizing: border-box;">
<span style="box-sizing: border-box;"><awsui-select-trigger initialized="true" style="box-sizing: border-box;"></awsui-select-trigger></span><br />
<div aria-autocomplete="list" class="awsui-select-trigger awsui-select-trigger-no-option awsui-select-trigger-variant-label" override-focus="" role="combobox" style="align-items: center; border-color: rgb(223, 51, 18); border-image: initial; border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 4px; box-sizing: border-box; color: #df3312; cursor: default; display: flex; justify-content: space-between; padding: 0.4rem 0px 0.4rem 7px; width: 362.5px;" tabindex="0">
<span style="box-sizing: border-box;"><span style="box-sizing: border-box;"></span><awsui-icon class="awsui-select-trigger-icon" initialized="true" style="box-sizing: border-box; display: inline-block; padding-right: 1rem;"><span class="awsui-icon awsui-icon-size-normal awsui-icon-variant-normal" style="box-sizing: border-box; color: currentcolor; display: inline-block; height: 2rem; padding: 0.2rem 0px; vertical-align: top; width: 1.6rem;"><svg alt="caret-down-filled" viewbox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><polygon class="filled stroke-linejoin-round" points="4 5 12 5 8 11 4 5"></polygon></svg></span></awsui-icon></span></div>
<span style="box-sizing: border-box;">
<awsui-select-dropdown initialized="true" style="box-sizing: border-box;"></awsui-select-dropdown></span></div>
<div class="awsui-multiselect-choice-area" style="box-sizing: border-box; display: flex; flex-wrap: wrap;">
<span style="box-sizing: border-box;"><awsui-select-token class="awsui-multiselect-token" initialized="true" style="box-sizing: border-box; display: flex; margin-right: 1rem; margin-top: 1rem;"></awsui-select-token></span><br />
<div class="awsui-select-token" style="align-items: flex-start; background-color: #f1faff; border: 1px solid rgb(0, 161, 201); box-sizing: border-box; color: #545b64; display: flex;">
<span style="box-sizing: border-box;"><awsui-select-option initialized="true" style="box-sizing: border-box; min-width: 0px; width: 328.5px;"></awsui-select-option></span><br />
<div class="awsui-select-option" data-value="subnet-44e59e0d" style="align-items: flex-start; box-sizing: border-box; color: #16191f; display: flex; padding: 0.4rem 1rem;" title="subnet-44e59e0d (10.0.0.0/19) | ap-northeast-1a Private subnet 1A">
<div class="awsui-select-option-content" style="box-sizing: border-box; display: flex; flex-direction: column; min-width: 0px; width: 308.5px;">
<div class="awsui-select-option-label-content" style="box-sizing: border-box; display: flex; flex-wrap: wrap; justify-content: space-between;">
<span style="box-sizing: border-box;"><span class="awsui-select-option-label" style="box-sizing: border-box; flex-wrap: wrap;">subnet-44e59e0d (10.0.0.0/19) | ap-northeast-1a Private subnet 1A</span></span></div>
</div>
</div>
<span style="box-sizing: border-box;">
</span></div>
<span style="box-sizing: border-box;">
</span></div>
</div>
<span style="box-sizing: border-box;">
</span></div>
<span style="box-sizing: border-box;">
</span></div>
</div>
</div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Anonymoushttp://www.blogger.com/profile/00458149907390232647noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-8579333127940201082018-02-08T11:08:00.001+08:002018-02-08T11:08:44.347+08:00linebot + serverless + typescript 開發時的小問題<br />
serverless 的 serverless offline 套件每次都會從重啟 webpack ,如果是typescript就會重新組譯很久,至少超過1秒,導致我的 linebot reply token 失效。<br />
<br />
用 handler.js ,不要寫handler.ts<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-13303302240249502018-02-06T16:02:00.000+08:002018-02-06T16:02:55.046+08:00免費 mongo host mlab .comhttps://mlab.com/<br />
有500mb<br />
測試好用<br />
<br />
要注意 db 的 user,從<br />
database => users 這裡開的才能用<span style="color: #569cd6; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;">const</span><span style="color: #9cdcfe; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;"> mongoString</span><span style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;"> =</span><span style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;"> </span><span style="color: #ce9178; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;">'mongodb://myUserAdmin:xxxx@ds125578.mlab.com:25578/abcxxxx</span><div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-14210195075662210752018-01-31T12:04:00.002+08:002018-01-31T12:04:17.770+08:00serverless (AWS lambda) + AWS mongodb cluster 照這個教學<br />
<a href="https://s3.amazonaws.com/quickstart-reference/mongodb/latest/doc/MongoDB_on_the_AWS_Cloud.pdf">https://s3.amazonaws.com/quickstart-reference/mongodb/latest/doc/MongoDB_on_the_AWS_Cloud.pdf</a><br />
<br />
<br />
<ol>
<li>選 new VPC </li>
<li>會到 cloudformation</li>
<li>下一步</li>
<ol>
<li>Availability Zones <=要全選</li>
<li>Number of Availability Zones <=全部</li>
<li>Allowed Bastion External Access CIDR Allowed CIDR <= 0.0.0.0/0</li>
<li>Key Pair Name <= key選本機原有的就好了<=之後還要從本機copy到,他開的機器,做ssh 的測試。</li>
<li>MongoDB Admin Username ...</li>
<li>MongoDB Admin Password ...</li>
</ol>
<li>下一步</li>
<li>約20分鐘</li>
<li>會開出兩台 ec2</li>
<ol>
<li>LinuxBastion <= 測試你的 mongo cluster 用的</li>
<li>PrimaryReplicaNode0 <= mongo cluster 只有 vpc 能連</li>
</ol>
<li>pdf 的測試方式為</li>
<ol>
<li>scp -i key .... 到 LinuxBastion
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px 'Courier New'; color: #000000}
</style>
<div class="p1">
scp –i mykey.pem mykey.pem ec2-user@Bastion-public-ip:/home/ec2-user/mykey.pem</div>
</li>
<li>ssh - i key PrimaryReplicaNode0的ip</li>
<li>mongo
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px 'Courier New'; color: #262626}
</style>
<div class="p1">
mongo</div>
<div class="p1">
use admin</div>
<div class="p1">
db.auth("admin", "YourAdminPassword") rs.printReplicationInfo()</div>
<span style="color: #262626; font-family: "Courier New"; font-size: 10px;">rs.status()</span></li>
</ol>
<li>應該都正常了</li>
</ol>
<div>
===lambda</div>
<ol><ol>
<li>我直接改這個範例做測試<br /><a href="https://github.com/serverless/examples/tree/master/aws-node-rest-api-mongodb">https://github.com/serverless/examples/tree/master/aws-node-rest-api-mongodb</a></li>
<li><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;">
<div>
<span style="color: #569cd6;"><br class="Apple-interchange-newline" />service</span>: <span style="color: #ce9178;">aws-node-rest-api-mongodb</span></div>
<br /><div>
<span style="color: #569cd6;">provider</span>:</div>
<div>
<span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">aws</span></div>
<div>
<span style="color: #569cd6;">region</span>: <span style="color: #ce9178;">ap-northeast-1 //記得region 要設對,不然找不到 sg</span></div>
<div>
<span style="color: #569cd6;">runtime</span>: <span style="color: #ce9178;">nodejs6.10</span></div>
<div>
<span style="color: #569cd6;">vpc</span>:</div>
<div>
<span style="color: #569cd6;">securityGroupIds</span>:</div>
<div>
- <span style="color: #ce9178;">"sg-db38a1xx" </span><span style="color: #ce9178;">//加這個</span></div>
<div>
<span style="color: #569cd6;">subnetIds</span>:</div>
<div>
- <span style="color: #ce9178;">"subnet-39dd6bxx" </span><span style="color: #ce9178;">//加這個</span></div>
<div>
- <span style="color: #ce9178;">"subnet-44e59exx" </span><span style="color: #ce9178;">//加這個</span></div>
<br /><div>
<span style="color: #569cd6;">functions</span>:</div>
<div>
<span style="color: #569cd6;">createUser</span>:</div>
<div>
<span style="color: #569cd6;">handler</span>: <span style="color: #ce9178;">handler.createUser</span></div>
<div>
<span style="color: #569cd6;">events</span>:</div>
<div>
- <span style="color: #569cd6;">http</span>:</div>
<div>
<span style="color: #569cd6;">path</span>: <span style="color: #ce9178;">user</span></div>
<div>
<span style="color: #569cd6;">method</span>: <span style="color: #ce9178;">post</span></div>
<div>
<span style="color: #569cd6;">cors</span>: <span style="color: #569cd6;">true</span></div>
<div>
<span style="color: #569cd6;">vpc</span>:</div>
<div>
<span style="color: #569cd6;">securityGroupIds</span>:</div>
<div>
- <span style="color: #ce9178;">"sg-db38a1xx" </span><span style="color: #ce9178;">//加這個</span></div>
<div>
<span style="color: #569cd6;">subnetIds</span>:</div>
<div>
- <span style="color: #ce9178;">"subnet-39dd6bxx" </span><span style="color: #ce9178;">//加這個</span></div>
<div>
- <span style="color: #ce9178;">"subnet-44e59exx" </span><span style="color: #ce9178;">//加這個</span></div>
</div>
</li>
<div>
<br /></div>
<div>
<br /></div>
<li>securityGroupIds <= 來自ec2 => <span style="background-color: #f0f9ff; color: #444444; font-family: arial; font-size: 13px; white-space: pre;">PrimaryReplicaNode0 </span>=> Security groups<br /> => 點進去 => 看 Source</li>
<li>Subnet ID <= 來自ec2 => <span style="background-color: #f0f9ff; color: #444444; font-family: arial; font-size: 13px; white-space: pre;">PrimaryReplicaNode0 </span>=> Subnet ID </li>
<li>sls deploy</li>
</ol>
</ol>
<div>
<div>
endpoints:</div>
<div>
POST - https:// x.execute-api.ap-northeast-1.amazonaws.com/dev/user</div>
<div>
PUT - https://x.execute-api.ap-northeast-1.amazonaws.com/dev/user/{id}</div>
<div>
DELETE - https://x.execute-api.ap-northeast-1.amazonaws.com/dev/user/{id}</div>
<div>
GET - https://x.execute-api.ap-northeast-1.amazonaws.com/dev/user/{id}</div>
</div>
<div>
<br /></div>
<div>
照這個試試吧!</div>
<div>
結束!</div>
<div>
<br /></div>
<div>
<br /></div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Anonymoushttp://www.blogger.com/profile/00458149907390232647noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-12683015872643942052018-01-27T15:58:00.001+08:002018-01-27T15:58:31.383+08:00中文網域 punnycode<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-10696783508111831972017-12-06T11:14:00.004+08:002017-12-06T11:14:52.704+08:00Node.js<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
開發botframework可以選擇c#或nodejs.<br style="box-sizing: border-box;" />選nodejs的好處就是用javascript開發,<br style="box-sizing: border-box;" />如果對javascript有一定熟悉度的話,<br style="box-sizing: border-box;" />可以省去學習成本。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
但Node.js<br style="box-sizing: border-box;" />今年真的蠻困擾的,<br style="box-sizing: border-box;" />例如 分支事件 (<a href="https://technews.tw/2017/09/07/node-js-leaders-fight-for-its-survival/)" style="background-color: transparent; box-sizing: border-box; color: #00a0e9; text-decoration-line: none; transition: all 0.2s;">https://technews.tw/2017/09/07/node-js-leaders-fight-for-its-survival/)</a><br style="box-sizing: border-box;" />node.js之父 公開說golang比nodejs好(<a href="https://www.mappingthejourney.com/single-post/2017/08/31/episode-8-interview-with-ryan-dahl-creator-of-nodejs/)" style="background-color: transparent; box-sizing: border-box; color: #00a0e9; text-decoration-line: none; transition: all 0.2s;">https://www.mappingthejourney.com/single-post/2017/08/31/episode-8-interview-with-ryan-dahl-creator-of-nodejs/)</a><br style="box-sizing: border-box;" />主要原因是 大家發現 Node.js 當網站訪問量大時,效能難以調挍等問題。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
不過其實還是可以再雲上針對這些問題做一些優化,<br style="box-sizing: border-box;" />例如: AWS 可以用cloudfront針對網頁做cache等設計,或是動態增生instance等.<br style="box-sizing: border-box;" />But,我就是不想管更後端的事情,才會從nodejs開始啊!!!!!!</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
算了,不管,總之,<br style="box-sizing: border-box;" />nodejs的生態系統完善,<br style="box-sizing: border-box;" />幾乎要什麼有什麼!<br style="box-sizing: border-box;" />而golang應該還有很長一段路要走。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
所以,<br style="box-sizing: border-box;" />還是先用nodejs吧!</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
而且在botframwork<br style="box-sizing: border-box;" /><a href="https://github.com/Microsoft/BotBuilder" style="background-color: transparent; box-sizing: border-box; color: #00a0e9; text-decoration-line: none; transition: all 0.2s;">https://github.com/Microsoft/BotBuilder</a><br style="box-sizing: border-box;" />已經有提供許多相關範例,<br style="box-sizing: border-box;" />大家可以參考使用。</div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-16262741679100282302017-12-06T11:14:00.000+08:002017-12-06T11:14:08.419+08:00Type script<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
開發Botframework 可以選c# 或node.js</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
而node.js是用JavaScript語法。<br style="box-sizing: border-box;" />故可以使用type script ,<br style="box-sizing: border-box;" />但主要是講botframework,<br style="box-sizing: border-box;" />故 Type script 的部份,<br style="box-sizing: border-box;" />讓我一章帶過吧。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
<a href="https://code.visualstudio.com/docs/languages/typescript" style="background-color: transparent; box-sizing: border-box; color: #00a0e9; text-decoration-line: none; transition: all 0.2s;">https://code.visualstudio.com/docs/languages/typescript</a><br style="box-sizing: border-box;" /><a href="https://www.gitbook.com/book/zhongsp/typescript-handbook/details" style="background-color: transparent; box-sizing: border-box; color: #00a0e9; text-decoration-line: none; transition: all 0.2s;">https://www.gitbook.com/book/zhongsp/typescript-handbook/details</a></div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
TypeScript具有类型系统,且是JavaScript的超集。 它可以编译成普通的JavaScript代码。 TypeScript支持任意浏览器,任意环境,任意系统并且是开源的。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
閉人在從 andorid 轉到開發 node.js應用時,<br style="box-sizing: border-box;" />最大的困擾就是,<br style="box-sizing: border-box;" />js無法再開發階段就可以偵錯。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
例如<br style="box-sizing: border-box;" />let a = i=>i+1;<br style="box-sizing: border-box;" />我想要的得到的是 數字 相加的結果。<br style="box-sizing: border-box;" />可是當我誤輸入 a("a"),也是會回傳 "a1",也是不會報錯,<br style="box-sizing: border-box;" />這可是天與地一般的差距啊。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
用 typescript<br style="box-sizing: border-box;" />let a =(i:int)=i+1<br style="box-sizing: border-box;" />若我輸入 a("a") 就會先報紅,<br style="box-sizing: border-box;" />而不用等到最後輸出結果時,<br style="box-sizing: border-box;" />才會發現這不是我要的,<br style="box-sizing: border-box;" />這是其中一個最基本的好處。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
*註 botframework 本身就是使用 type script 做開發。</div>
<div>
<br /></div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-81759381266473725442017-12-06T11:13:00.002+08:002017-12-06T11:13:30.037+08:00前言. 選擇 botframework 的優缺點<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
假設你是要開發FB的chatbot,<br style="box-sizing: border-box;" />且不具有程式背景(或懶得code),<br style="box-sizing: border-box;" />但邏況能力還行的話,<br style="box-sizing: border-box;" />那建議你可以直接採用 chatfuel ,<br style="box-sizing: border-box;" />chatfuel 聽說是台灣團隊所開發,<br style="box-sizing: border-box;" />且直接被FB給投資。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
重點是,<br style="box-sizing: border-box;" />Chatfuel有UI介面,<br style="box-sizing: border-box;" />你只要拉一拉 連一連,就可以完成大部分的需求了,幾乎用不到任何code,但如果你想寫,也是有部分的支援。<br style="box-sizing: border-box;" />而且,<br style="box-sizing: border-box;" />chatfuel權限是直接被FB開啟的,<br style="box-sizing: border-box;" />你不需要去跟FB要權限就可以做很多事,<br style="box-sizing: border-box;" />例如 取得user profile...(申請fb權限,要審核,真的很麻煩!)<br style="box-sizing: border-box;" />而且!!! 台灣某大銀行的FB chatbot是用企畫人員 chatfuel 拉出來,<br style="box-sizing: border-box;" />然後該銀行就發新聞稿,自已站在潮流之上了,而且運作的還ok!。(廢話,chatfuel這麼多人在maintain 怎麼可能會差)</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
但是,<br style="box-sizing: border-box;" />相對的,當然也會受限於Chatfuel的UI介面,<br style="box-sizing: border-box;" />而使你的Chat bot 無法靈活開發,<br style="box-sizing: border-box;" />達到一些,你所希望的功能,</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
另外,因為A.I.是採取chatfuel所訓練好的,<br style="box-sizing: border-box;" />所以每個Bot 可能會交談起來都是固定的模式。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
假設你有跨平臺的需求slack telegram Skype...<br style="box-sizing: border-box;" />也是不能直接套用的。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
如果你會 c# 或 node js,<br style="box-sizing: border-box;" />那你就可以試一試 botframework,<br style="box-sizing: border-box;" />botframework其實就是一套腳本+狀態的機制。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
採用的好處就是你直接可以依照這個框架,來撰寫你的整個chatbot流程,<br style="box-sizing: border-box;" />而不用從 message api 開始作一系列的發展。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
但目前為止,最大的壞處,就是m$因為該公司有Cloud的產品,<br style="box-sizing: border-box;" />為了帶動該Cloud的發展,<br style="box-sizing: border-box;" />硬是綁在一起,<br style="box-sizing: border-box;" />導致這麼好的一個框架,<br style="box-sizing: border-box;" />得先連到美國作轉發,<br style="box-sizing: border-box;" />所以整個就會慢。</div>
<div style="background-color: white; box-sizing: border-box; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px; line-height: 1.7; margin-bottom: 26px;">
*註:因為 Line不被 dev.botframework.com 所支持,<br style="box-sizing: border-box;" />所以我自幹line builder 時,<br style="box-sizing: border-box;" />就順便把轉發這個問題給幹掉了。<br style="box-sizing: border-box;" />不過我FB messenger 的部分還是先採用 dev.botframework.com ,因為 npm 上的 FB builder都沒在做更新。<br style="box-sizing: border-box;" />而FB又很愛改,所以先採用好了,以後再看看要不要幫忙 maintain FB builder.</div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-32989710669663344592017-10-17T11:09:00.003+08:002017-10-17T11:09:59.642+08:00connect pppoe by applescript<div class="p1">
<span class="s1"><b>tell</b> </span><span class="s2"><i>application</i></span><span class="s1"> "System Events"</span></div>
<div class="p2">
<span class="s3"><span class="Apple-tab-span"> </span><b>tell</b> </span><span class="s1">network preferences</span></div>
<div class="p3">
<span class="s3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s1"><b>connect</b></span><span class="s3"> </span><span class="s1"><i>service</i></span><span class="s3"> "PPPoE"</span></div>
<div class="p4">
<span class="s1"><span class="Apple-tab-span"> </span><b>end</b> <b>tell</b></span></div>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 41.6px; text-indent: -41.6px; font: 12.0px Verdana}
p.p2 {margin: 0.0px 0.0px 0.0px 83.2px; text-indent: -83.2px; font: 12.0px Verdana; color: #812fdc}
p.p3 {margin: 0.0px 0.0px 0.0px 124.8px; text-indent: -124.9px; font: 12.0px Verdana; color: #0433ff}
p.p4 {margin: 0.0px 0.0px 0.0px 83.2px; text-indent: -83.2px; font: 12.0px Verdana}
span.s1 {font-variant-ligatures: no-common-ligatures}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #0433ff}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #000000}
span.Apple-tab-span {white-space:pre}
</style>
<br />
<div class="p1">
<span class="s1"><b>end</b> <b>tell</b></span></div>
<div class="p1">
<span class="s1"><b><br /></b></span></div>
<div class="p1">
<span class="s1"><b>tell</b> </span><span class="s2"><i>application</i></span><span class="s1"> "System Events"</span></div>
<div class="p2">
<span class="s3"><span class="Apple-tab-span"> </span><b>tell</b> </span><span class="s1">network preferences</span></div>
<div class="p3">
<span class="s3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s1"><b>disconnect</b></span><span class="s3"> </span><span class="s1"><i>service</i></span><span class="s3"> "PPPoE"</span></div>
<div class="p4">
<span class="s1"><span class="Apple-tab-span"> </span><b>end</b> <b>tell</b></span></div>
<div class="p1">
<span class="s1">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 41.6px; text-indent: -41.6px; font: 12.0px Verdana}
p.p2 {margin: 0.0px 0.0px 0.0px 78.5px; text-indent: -78.6px; font: 12.0px Verdana; color: #812fdc}
p.p3 {margin: 0.0px 0.0px 0.0px 117.8px; text-indent: -117.8px; font: 12.0px Verdana; color: #0433ff}
p.p4 {margin: 0.0px 0.0px 0.0px 78.5px; text-indent: -78.6px; font: 12.0px Verdana}
span.s1 {font-variant-ligatures: no-common-ligatures}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #0433ff}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #000000}
span.Apple-tab-span {white-space:pre}
</style>
</span></div>
<div class="p1">
<span class="s1"><b>end</b> <b>tell</b></span></div>
<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-91767401116004157012017-09-11T16:06:00.006+08:002017-09-11T16:06:56.217+08:00爬蟲 chromeless<a href="https://github.com/graphcool/chromeless" target="_blank">https://github.com/graphcool/chromeless</a><br />
可以無套串 AWS lambda<br />
用serverless這套<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Wolkehttp://www.blogger.com/profile/02425204241148879794noreply@blogger.com0tag:blogger.com,1999:blog-7317433007237940535.post-89865137367273924092017-09-02T13:15:00.004+08:002017-09-02T13:15:38.603+08:00aws cloudfront s3 image 設定header expires 之路s3 加 lamda function<br />
直接加上metadata<br />
加content type<br />
加expires<br />
<br />
cloudfront不會這麼快更新,所以要invalidate<div class="blogger-post-footer">每個人都很單純,大家都是夥伴。</div>Anonymoushttp://www.blogger.com/profile/00458149907390232647noreply@blogger.com0