Best JavaScript code snippet using wpt
bot.js
Source:bot.js
1const { response } = require('express');2var express = require('express');3var router = express.Router();4const request = require('request');5const { checkTripAvaliable, checkOwnerTrip, RecommendEat, RecommendTravel, RecommendSleep, checkWeather, checkPayBill, checkTripPerDay } = require('../controller/botController');6router.post('/webhook', async (req, res) => {7 // let msg = req.body.events[0]8 // if (msg.type === "message" && msg.message.type === "text") {9 let msg = req.body.events[0].message.text10 let reply_token = req.body.events[0].replyToken11 // let locationMsg = req.body.message.type12 let weatherMsg = msg.substring(0, 7)13 let typeEat = msg.substring(0, 7)14 let typeTravel = msg.substring(0, 10)15 let typeSleep = msg.substring(0, 7)16 if (msg === "à¸à¸²à¸à¸²à¸£à¸¢à¹à¹à¸à¹") {17 replyProfessor(reply_token)18 }19 else if (typeEat === "#à¸à¸µà¹à¸à¸´à¸") {20 let provinceMsg = req.body.events[0].message.text.substring(8)21 let locationEat = await RecommendEat(provinceMsg);22 replyRecommendEat(reply_token, locationEat)23 }24 else if (typeTravel === "#à¸à¸µà¹à¹à¸à¸µà¹à¸¢à¸§") {25 let provinceMsg = req.body.events[0].message.text.substring(11)26 let locationTravel = await RecommendTravel(provinceMsg);27 replyRecommendTravel(reply_token, locationTravel)28 }29 else if (typeSleep === "#à¸à¸µà¹à¸à¸±à¸") {30 let provinceMsg = req.body.events[0].message.text.substring(8)31 let locationSleep = await RecommendSleep(provinceMsg);32 replyRecommendSleep(reply_token, locationSleep)33 }34 else if (weatherMsg === "#à¸à¸²à¸à¸²à¸¨,") {35 let provinceWeather = req.body.events[0].message.text.substring(7)36 let weather = await checkWeather(provinceWeather);37 let temp = weather.forecasts[0].data.tc_max;38 replyCheckWeather(reply_token, temp)39 }40 else if (msg === "#สรà¹à¸²à¸à¸à¸£à¸´à¸") {41 let groundId = req.body.events[0].source.groupId42 let haveTrip = await checkTripAvaliable(groundId);43 if (haveTrip) {44 replyNotCreate(reply_token, msg)45 } else {46 replyCreate(reply_token, msg)47 }48 }49 else if (msg === "#à¸à¸¹à¹à¸à¸") {50 let groundId = req.body.events[0].source.groupId51 let haveTrip = await checkTripAvaliable(groundId);52 if (haveTrip) {53 replyPlan(reply_token, msg)54 } else {55 replyCantSeePlan(reply_token, msg)56 }57 }58 else if (msg === "à¸à¸¹à¹à¸à¸à¸à¸±à¹à¸à¸«à¸¡à¸") {59 replyPlanAll(reply_token, msg)60 }61 else if (msg === "à¸à¸¹à¹à¸à¸à¸§à¸±à¸à¸à¸µà¹") {62 let groupId = req.body.events[0].source.groupId63 let perday = await checkTripPerDay(groupId)64 if (perday.tripName) {65 replyPlanPerDay(reply_token, perday)66 } else {67 replyNotBill(reply_token)68 }69 }70 else if (msg === "#à¸à¹à¸§à¸¢") {71 replyHelp(reply_token, msg)72 }73 else if (msg === "วิà¸à¸µà¸à¸²à¸£à¸ªà¸£à¹à¸²à¸à¸à¸£à¸´à¸") {74 replyHelpCreateTrip(reply_token, msg)75 }76 else if (msg === "วิà¸à¸µà¸à¸²à¸£à¸à¸¹à¹à¸à¸") {77 replyHelpPlan(reply_token, msg)78 }79 else if (msg === "วิà¸à¸µà¸à¸²à¸£à¸à¸±à¸à¸à¸²à¸£à¸à¸´à¸¥") {80 replyHelpBill(reply_token, msg)81 }82 else if (msg === "#à¹à¸à¸°à¸à¸³") {83 replyRecommend(reply_token, msg)84 }85 else if (msg === "#à¸à¸²à¸à¸²à¸¨") {86 replyWeather(reply_token, msg)87 }88 // get locations here89 else if (msg === "#à¸à¸´à¸à¸à¹à¸") {90 replyContact(reply_token, msg)91 }92 else if (msg === "#à¸à¸´à¸¥") {93 replyBill(reply_token, msg)94 }95 else if (msg === "#สรà¹à¸²à¸à¸à¸´à¸¥") {96 replyCreateBill(reply_token, msg)97 }98 else if (msg === "#à¸à¸¹à¸à¸´à¸¥") {99 let groupId = req.body.events[0].source.groupId100 let bill = await checkPayBill(groupId)101 if (bill.billName) {102 replySeeBill(reply_token, bill)103 } else {104 replyNotBill(reply_token)105 }106 }107 else if (msg === "#location") {108 reply(req)109 }110 else if (msg === "#ยà¸à¹à¸¥à¸´à¸à¸à¸£à¸´à¸") {111 replyDeleteTrip(reply_token, msg)112 }113 else if (msg === "#à¸à¸´à¸à¸à¸£à¸´à¸") {114 let userId = req.body.events[0].source.userId115 let groupId = req.body.events[0].source.groupId116 let checkOwner = await checkOwnerTrip(groupId, userId);117 if (checkOwner) {118 replyRating(reply_token, msg)119 } else {120 reply(req)121 }122 }123 // reply(req)124 res.sendStatus(200)125})126//-------------------------------function-------------------------------//127const reply = req => {128 let headers = {129 'Content-Type': 'application/json',130 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'131 }132 let body = JSON.stringify({133 replyToken: req.body.events[0].replyToken,134 messages: [135 {136 type: "text",137 text: JSON.stringify(req.body)138 }139 ]140 })141 request.post({142 url: 'https://api.line.me/v2/bot/message/reply',143 headers: headers,144 body: body145 }, (err, res, body) => {146 console.log('status = ' + res.statusCode);147 });148};149function replyBased(reply_token, provinceMsg) {150 let headers = {151 'Content-Type': 'application/json',152 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'153 }154 let body = JSON.stringify({155 replyToken: reply_token,156 messages: [157 {158 type: 'text',159 text: provinceMsg160 }161 ]162 })163 request.post({164 url: 'https://api.line.me/v2/bot/message/reply',165 headers: headers,166 body: body167 }, (err, res, body) => {168 console.log('status = ' + res.statusCode);169 });170}171function replyRecommendEat(reply_token, locationEat) {172 let headers = {173 'Content-Type': 'application/json',174 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'175 }176 let body = JSON.stringify({177 replyToken: reply_token,178 messages: [179 {180 type: 'text',181 text: locationEat182 }183 ]184 })185 request.post({186 url: 'https://api.line.me/v2/bot/message/reply',187 headers: headers,188 body: body189 }, (err, res, body) => {190 console.log('status = ' + res.statusCode);191 });192}193function replyRecon(reply_token, provinceMsg) {194 let headers = {195 'Content-Type': 'application/json',196 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'197 }198 let body = JSON.stringify({199 replyToken: reply_token,200 messages: [201 {202 type: 'text',203 text: provinceMsg204 }205 ]206 })207 request.post({208 url: 'https://api.line.me/v2/bot/message/reply',209 headers: headers,210 body: body211 }, (err, res, body) => {212 console.log('status = ' + res.statusCode);213 });214}215function replyProfessor(reply_token) {216 let headers = {217 'Content-Type': 'application/json',218 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'219 }220 let body = JSON.stringify({221 replyToken: reply_token,222 messages: [223 {224 type: 'text',225 text: 'â¥'226 }227 ]228 })229 request.post({230 url: 'https://api.line.me/v2/bot/message/reply',231 headers: headers,232 body: body233 }, (err, res, body) => {234 console.log('status = ' + res.statusCode);235 });236}237function replyCheckWeather(reply_token, temp) {238 let headers = {239 'Content-Type': 'application/json',240 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'241 }242 let body = JSON.stringify({243 replyToken: reply_token,244 messages: [245 {246 type: 'text',247 text: temp + " à¸à¸à¸¨à¸²"248 }249 ]250 })251 request.post({252 url: 'https://api.line.me/v2/bot/message/reply',253 headers: headers,254 body: body255 }, (err, res, body) => {256 console.log('status = ' + res.statusCode);257 });258}259function replyNotCreate(reply_token, msg) {260 let headers = {261 'Content-Type': 'application/json',262 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'263 }264 let body = JSON.stringify({265 replyToken: reply_token,266 messages: [267 {268 type: 'text',269 text: msg270 },271 {272 type: "flex",273 altText: "Flex Message",274 contents: {275 type: "bubble",276 body: {277 layout: "vertical",278 contents: [279 {280 type: "text",281 align: "center",282 weight: "bold",283 text: "à¸à¸à¸°à¸à¸µà¹à¸¡à¸µà¸à¸£à¸´à¸à¸à¸µà¹à¸à¸³à¸¥à¸±à¸à¹à¸à¸µà¹à¸¢à¸§à¸à¸¢à¸¹à¹à¹à¸¥à¹à¸§?"284 }285 ],286 type: "box"287 },288 direction: "ltr",289 footer: {290 type: "box",291 layout: "vertical",292 contents: [293 {294 action: {295 label: "à¸à¸¹à¹à¸à¸à¸à¸±à¹à¸à¸«à¸¡à¸",296 type: "uri",297 uri: "https://liff.line.me/1653975470-4Webv3MY"298 },299 type: "button",300 color: "#C25738",301 height: "sm",302 margin: "xs",303 style: "primary"304 },305 {306 margin: "xs",307 color: "#C25738",308 height: "sm",309 style: "primary",310 action: {311 data: "text",312 label: "à¸à¸¹à¹à¸à¸à¸§à¸±à¸à¸à¸µà¹",313 type: "postback",314 text: "à¸à¸¹à¹à¸à¸à¸§à¸±à¸à¸à¸µà¹"315 },316 type: "button"317 }318 ]319 }320 }321 }322 ]323 })324 request.post({325 url: 'https://api.line.me/v2/bot/message/reply',326 headers: headers,327 body: body328 }, (err, res, body) => {329 console.log('status = ' + res.statusCode);330 });331}332function replyCreate(reply_token, msg) {333 let headers = {334 'Content-Type': 'application/json',335 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'336 }337 let body = JSON.stringify({338 replyToken: reply_token,339 messages: [340 {341 type: 'text',342 text: msg343 },344 {345 type: "flex",346 altText: "Flex Message",347 contents: {348 type: "bubble",349 body: {350 layout: "vertical",351 contents: [352 {353 type: "text",354 align: "center",355 weight: "bold",356 text: "à¸à¸£à¹à¸à¸¡à¸à¸µà¹à¸à¸°à¸ªà¸£à¹à¸²à¸à¸à¸£à¸´à¸à¹à¸¥à¹à¸§à¹à¸à¹à¹à¸«à¸¡?"357 }358 ],359 type: "box"360 },361 direction: "ltr",362 footer: {363 type: "box",364 layout: "vertical",365 contents: [366 {367 action: {368 label: "สรà¹à¸²à¸à¸à¸£à¸´à¸",369 type: "uri",370 uri: "https://liff.line.me/1653975470-jV83lv9w"371 },372 type: "button",373 color: "#C25738",374 height: "sm",375 margin: "xs",376 style: "primary"377 }378 ]379 }380 }381 }382 ]383 })384 request.post({385 url: 'https://api.line.me/v2/bot/message/reply',386 headers: headers,387 body: body388 }, (err, res, body) => {389 console.log('status = ' + res.statusCode);390 });391}392function replyPlan(reply_token, msg) {393 let headers = {394 'Content-Type': 'application/json',395 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'396 }397 let body = JSON.stringify({398 replyToken: reply_token,399 messages: [400 {401 type: 'text',402 text: msg403 },404 {405 type: "flex",406 altText: "Flex Message",407 contents: {408 type: "bubble",409 body: {410 layout: "vertical",411 contents: [412 {413 type: "text",414 align: "center",415 weight: "bold",416 text: "à¸à¸¢à¸²à¸à¸à¸¹à¹à¸à¸à¹à¸«à¸à¸à¸£à¸±à¸?"417 }418 ],419 type: "box"420 },421 direction: "ltr",422 footer: {423 type: "box",424 layout: "vertical",425 contents: [426 {427 action: {428 label: "à¸à¸¹à¹à¸à¸à¸à¸±à¹à¸à¸«à¸¡à¸",429 type: "uri",430 uri: "https://liff.line.me/1653975470-4Webv3MY"431 },432 type: "button",433 color: "#C25738",434 height: "sm",435 margin: "xs",436 style: "primary"437 },438 {439 margin: "xs",440 color: "#C25738",441 height: "sm",442 style: "primary",443 action: {444 data: "text",445 label: "à¸à¸¹à¹à¸à¸à¸§à¸±à¸à¸à¸µà¹",446 type: "postback",447 text: "à¸à¸¹à¹à¸à¸à¸§à¸±à¸à¸à¸µà¹"448 },449 type: "button"450 }451 ]452 }453 }454 }455 ]456 })457 request.post({458 url: 'https://api.line.me/v2/bot/message/reply',459 headers: headers,460 body: body461 }, (err, res, body) => {462 console.log('status = ' + res.statusCode);463 });464}465function replyCantSeePlan(reply_token, msg) {466 let headers = {467 'Content-Type': 'application/json',468 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'469 }470 let body = JSON.stringify({471 replyToken: reply_token,472 messages: [473 {474 type: 'text',475 text: msg476 },477 {478 type: "flex",479 altText: "Flex Message",480 contents: {481 type: "bubble",482 body: {483 layout: "vertical",484 contents: [485 {486 type: "text",487 align: "center",488 weight: "bold",489 text: "à¸à¸¸à¸à¸¢à¸±à¸à¹à¸¡à¹à¸¡à¸µà¸à¸£à¸´à¸à¹à¸à¸à¸à¸°à¸à¸µà¹ มาสรà¹à¸²à¸à¸à¸£à¸´à¸à¸à¸±à¸à¹à¸¥à¸¢!"490 }491 ],492 type: "box"493 },494 direction: "ltr",495 footer: {496 type: "box",497 layout: "vertical",498 contents: [499 {500 action: {501 label: "สรà¹à¸²à¸à¸à¸£à¸´à¸",502 type: "uri",503 uri: "https://liff.line.me/1653975470-jV83lv9w"504 },505 type: "button",506 color: "#C25738",507 height: "sm",508 margin: "xs",509 style: "primary"510 }511 ]512 }513 }514 }515 ]516 })517 request.post({518 url: 'https://api.line.me/v2/bot/message/reply',519 headers: headers,520 body: body521 }, (err, res, body) => {522 console.log('status = ' + res.statusCode);523 });524}525function replyPlanPerDay(reply_token, perday) {526 let contentEventName = []527 perday.totalDate[0].events.map((u) => contentEventName.push({528 type: "text",529 text: u.eventName530 }))531 let contentEventTime = []532 perday.totalDate[0].events.map((u) => contentEventTime.push({533 type: "text",534 text: u.startEvent + "à¸." + " - " + u.endEvent + "à¸."535 }))536 let headers = {537 'Content-Type': 'application/json',538 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'539 }540 let body = JSON.stringify({541 replyToken: reply_token,542 messages: [543 {544 type: "flex",545 altText: "Flex Message",546 contents: {547 type: "bubble",548 size: "mega",549 body: {550 type: "box",551 layout: "vertical",552 contents: [553 {554 type: "box",555 layout: "vertical",556 contents: [],557 flex: 2,558 backgroundColor: "#C15638"559 },560 {561 type: "box",562 layout: "vertical",563 contents: [],564 flex: 3565 },566 {567 type: "box",568 layout: "vertical",569 contents: contentEventName,570 width: "50%",571 position: "absolute",572 offsetTop: "50%",573 offsetStart: "15px"574 },575 {576 type: "box",577 layout: "vertical",578 contents: contentEventTime,579 position: "absolute",580 offsetTop: "50%",581 offsetEnd: "15px"582 },583 {584 type: "box",585 layout: "vertical",586 contents: [587 {588 type: "text",589 text: perday.province,590 size: "lg",591 color: "#FFFFFF"592 },593 {594 type: "text",595 text: perday.tripName,596 size: "xxl",597 color: "#FFFFFF"598 }599 ],600 position: "absolute",601 offsetTop: "15px",602 offsetStart: "15px"603 }604 ],605 height: "240px",606 paddingAll: "0px"607 },608 footer: {609 type: "box",610 layout: "vertical",611 contents: [612 {613 type: "button",614 action: {615 type: "uri",616 label: "à¸à¸¹à¸à¸£à¸´à¸à¸à¸±à¹à¸à¸«à¸¡à¸",617 uri: "https://liff.line.me/1653975470-4Webv3MY"618 },619 style: "primary",620 color: "#C15638"621 }622 ]623 },624 styles: {625 footer: {626 separator: true627 }628 }629 }630 }631 ]632 })633 request.post({634 url: 'https://api.line.me/v2/bot/message/reply',635 headers: headers,636 body: body637 }, (err, res, body) => {638 console.log('status = ' + res.statusCode);639 });640}641function replyPlanAll(reply_token, msg) {642 let headers = {643 'Content-Type': 'application/json',644 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'645 }646 let body = JSON.stringify({647 replyToken: reply_token,648 messages: [649 {650 type: 'text',651 text: "lineliff here"652 },653 ]654 })655 request.post({656 url: 'https://api.line.me/v2/bot/message/reply',657 headers: headers,658 body: body659 }, (err, res, body) => {660 console.log('status = ' + res.statusCode);661 });662}663function replyBill(reply_token, msg) {664 let headers = {665 'Content-Type': 'application/json',666 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'667 }668 let body = JSON.stringify({669 replyToken: reply_token,670 messages: [671 {672 type: "text",673 text: "à¸à¸°à¸à¸³à¸à¸°à¹à¸£à¸à¸µà¸à¸£à¸±à¸?",674 quickReply: {675 items: [676 {677 type: "action",678 action: {679 type: "message",680 label: "สรà¹à¸²à¸à¸à¸´à¸¥",681 text: "#สรà¹à¸²à¸à¸à¸´à¸¥"682 }683 },684 {685 type: "action",686 action: {687 type: "message",688 label: "à¸à¸¹à¸à¸´à¸¥",689 text: "#à¸à¸¹à¸à¸´à¸¥"690 }691 }692 ]693 }694 }695 ]696 })697 request.post({698 url: 'https://api.line.me/v2/bot/message/reply',699 headers: headers,700 body: body701 }, (err, res, body) => {702 console.log('status = ' + res.statusCode);703 });704}705function replyCreateBill(reply_token, msg) {706 let headers = {707 'Content-Type': 'application/json',708 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'709 }710 let body = JSON.stringify({711 replyToken: reply_token,712 messages: [713 {714 type: 'text',715 text: msg716 },717 {718 type: "flex",719 altText: "Flex Message",720 contents: {721 type: "bubble",722 body: {723 layout: "vertical",724 contents: [725 {726 type: "text",727 align: "center",728 weight: "bold",729 text: "มาสรà¹à¸²à¸à¸à¸´à¸¥à¸à¸±à¸à¹à¸à¸à¸°!"730 }731 ],732 type: "box"733 },734 direction: "ltr",735 footer: {736 type: "box",737 layout: "vertical",738 contents: [739 {740 action: {741 label: "สรà¹à¸²à¸à¸à¸´à¸¥",742 type: "uri",743 uri: "https://liff.line.me/1653975470-6rJYy1Qm"744 },745 type: "button",746 color: "#C25738",747 height: "sm",748 margin: "xs",749 style: "primary"750 }751 ]752 }753 }754 }755 ]756 })757 request.post({758 url: 'https://api.line.me/v2/bot/message/reply',759 headers: headers,760 body: body761 }, (err, res, body) => {762 console.log('status = ' + res.statusCode);763 });764}765function replyNotBill(reply_token) {766 let headers = {767 'Content-Type': 'application/json',768 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'769 }770 let body = JSON.stringify({771 replyToken: reply_token,772 messages: [773 {774 type: "flex",775 altText: "Flex Message",776 contents: {777 type: "bubble",778 body: {779 layout: "vertical",780 contents: [781 {782 type: "text",783 align: "center",784 weight: "bold",785 text: "à¸à¸à¸°à¸à¸µà¹à¸¢à¸±à¸à¹à¸¡à¹à¸¡à¸µà¸à¸´à¸¥ มาสรà¹à¸²à¸à¸à¸´à¸¥à¸à¸±à¸à¹à¸à¸à¸°!"786 }787 ],788 type: "box"789 },790 direction: "ltr",791 footer: {792 type: "box",793 layout: "vertical",794 contents: [795 {796 action: {797 label: "สรà¹à¸²à¸à¸à¸´à¸¥",798 type: "uri",799 uri: "https://liff.line.me/1653975470-6rJYy1Qm"800 },801 type: "button",802 color: "#C25738",803 height: "sm",804 margin: "xs",805 style: "primary"806 }807 ]808 }809 }810 }811 ]812 })813 request.post({814 url: 'https://api.line.me/v2/bot/message/reply',815 headers: headers,816 body: body817 }, (err, res, body) => {818 console.log('status = ' + res.statusCode);819 });820}821function replySeeBill(reply_token, bill) {822 let contentName = []823 bill.user.map((u) => contentName.push({824 type: "text",825 text: u.fName826 }))827 let contentCost = []828 bill.user.map((u) => contentCost.push({829 type: "text",830 text: (bill.totalCost / bill.user.length).toFixed(2) + " ฿"831 }))832 let headers = {833 'Content-Type': 'application/json',834 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'835 }836 let body = JSON.stringify({837 replyToken: reply_token,838 messages: [839 {840 type: "flex",841 altText: "Flex Message",842 contents: {843 type: "bubble",844 size: "mega",845 body: {846 type: "box",847 layout: "vertical",848 contents: [849 {850 type: "box",851 layout: "vertical",852 contents: [],853 flex: 2,854 backgroundColor: "#C15638"855 },856 {857 type: "box",858 layout: "vertical",859 contents: [],860 flex: 3861 },862 {863 type: "box",864 layout: "vertical",865 contents: contentName,866 width: "50%",867 position: "absolute",868 offsetTop: "50%",869 offsetStart: "15px"870 },871 {872 type: "box",873 layout: "vertical",874 contents: contentCost,875 position: "absolute",876 offsetTop: "50%",877 offsetEnd: "15px"878 },879 {880 type: "box",881 layout: "vertical",882 contents: [883 {884 type: "text",885 text: bill.billName,886 size: "lg",887 color: "#FFFFFF"888 },889 {890 type: "text",891 text: bill.totalCost + ' ฿',892 size: "xxl",893 color: "#FFFFFF"894 }895 ],896 position: "absolute",897 offsetTop: "15px",898 offsetStart: "15px"899 }900 ],901 height: "240px",902 paddingAll: "0px"903 },904 footer: {905 type: "box",906 layout: "vertical",907 contents: [908 {909 type: "button",910 action: {911 type: "uri",912 label: "à¹à¸à¸£à¸à¹à¸²à¸¢à¹à¸¥à¹à¸§à¸à¹à¸²à¸",913 uri: "https://liff.line.me/1653975470-DEq4WP1a"914 }915 },916 {917 type: "button",918 action: {919 type: "uri",920 label: "à¸à¹à¸²à¸¢à¹à¸à¸´à¸",921 uri: "https://liff.line.me/1653975470-JyVQ0Xr9"922 },923 style: "primary",924 color: "#C15638"925 }926 ]927 },928 styles: {929 footer: {930 separator: true931 }932 }933 }934 }935 ]936 })937 request.post({938 url: 'https://api.line.me/v2/bot/message/reply',939 headers: headers,940 body: body941 }, (err, res, body) => {942 console.log('status = ' + res.statusCode);943 });944}945function replyWeather(reply_token, msg) {946 let headers = {947 'Content-Type': 'application/json',948 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'949 }950 let body = JSON.stringify({951 replyToken: reply_token,952 messages: [953 {954 type: "text",955 text: " à¸à¸¢à¸²à¸à¸£à¸¹à¹à¸ªà¸ าà¸à¸à¸²à¸à¸²à¸¨à¸à¸µà¹à¹à¸«à¸à¸à¸£à¸±à¸?",956 quickReply: {957 items: [958 {959 type: "action",960 action: {961 type: "location",962 label: "Location"963 }964 }965 ]966 }967 }968 ]969 })970 request.post({971 url: 'https://api.line.me/v2/bot/message/reply',972 headers: headers,973 body: body974 }, (err, res, body) => {975 console.log('status = ' + res.statusCode);976 });977}978// function replyWeatherMaps(reply_token, msg) {979// let headers = {980// 'Content-Type': 'application/json',981// 'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImIwYmYzY2E2YzFiZTI3ZjZkOGY5NDFhNjgyMmY2MjE4ZWViMDIzMzYyNDE1NDA3Nzk1NzIxNGYwYTkxNjJiNzljYjZjZTc1MGM4MzEwNGRmIn0.eyJhdWQiOiIyIiwianRpIjoiYjBiZjNjYTZjMWJlMjdmNmQ4Zjk0MWE2ODIyZjYyMThlZWIwMjMzNjI0MTU0MDc3OTU3MjE0ZjBhOTE2MmI3OWNiNmNlNzUwYzgzMTA0ZGYiLCJpYXQiOjE2MDA1MzE1NTEsIm5iZiI6MTYwMDUzMTU1MSwiZXhwIjoxNjMyMDY3NTUxLCJzdWIiOiI5NzkiLCJzY29wZXMiOltdfQ.FMch8VXWx957OH1FjR28JKaHcfxsHV4fSL5Scc_hflnRClf95iND0YaqbxNkiUX7f0TuhxzIMl0GFbrvQ6NKXOvYSj4dfU8jJMuDDG3QZTkLgExXDvQtsH2Ui5ZpAhHgPtkK7lPV1fGsQG_d5Ad9GjOD_oxgZygm6_iSM2ERh76kd2YywxFuN3_pBrBmLOm7kNFYatm_Ntg0Xir7NnnKVsE_S2RYYqsIoM5ZRjrWKK4A0Erk6WiXtXeD0fAFuv-Ope8cG_4Bh3VBgvhbFW3jNZ1OniutHYcba2Bv_P_WoL-xrRzxxvMSIKNXLfneoLNW5HPo0DNV273ZemPgbC6x3LdeFOCxtjy1YA-DZ2tTuQycm32CrD3GJXxQAaYC9TjthkCLXrcu40S6D2jQWOt-brkwhUuY2vNEdVx0YZDZXZ34TWLXYLVoJs-lSMI_NMtMdhhxo29gXr07YJFB7E8NvN2HSVA_Y4lCsz8KIP7ZNhK8QeuR3raxuFPxBM-3e0a-sEiQs3c5NvzEZhLrVD-ldxkCD5t6PdtgUOgaWk9tUfltrZ0sQsga6RFx0sj-R7TvwPHA8oOjarVIc-e-2vixGxipSmXccZ47-SxfAXUn91XfhZwg3zs4UyrVEjy1n62lFLGfmzMSOL05w9fLdJd7cMOs14d67ldnWvXQGV-aQL4'982// }983// exports.LineBotPush = functions.https.onRequest((req, res) => {984// events.location985// return request({986// method: `GET`,987// uri: `https://data.tmd.go.th/nwpapi/v1/forecast/location/daily/at`,988// json: true989// }).then((response) => {990// const message = `City: ${response.name}\nWeather: ${response.weather[0].description}\nTemperature: ${response.main.temp}`;991// return push(res, message);992// }).catch((error) => {993// return res.status(500).send(error);994// });995// });996// let body = JSON.stringify({997// replyToken: reply_token,998// messages: [999// {1000// weather_forecast: {1001// locations: [1002// {1003// location: {1004// lat: 13.0068,1005// lon: 100.08291006// },1007// forecasts: [1008// {1009// time: "2017-08-17T00:00:00+07:00",1010// data: {1011// rh: 88.54,1012// tc_max: 28.561013// }1014// },1015// {1016// time: "2017-08-18T00:00:00+07:00",1017// data: {1018// rh: 87.44,1019// tc_max: 27.211020// }1021// }1022// ]1023// }1024// ]1025// }1026// }1027// ]1028// })1029// request.post({1030// url: 'https://api.line.me/v2/bot/message/reply',1031// headers: headers,1032// body: body1033// }, (err, res, body) => {1034// console.log('status = ' + res.statusCode);1035// });1036// }1037function replyContact(reply_token, msg) {1038 let headers = {1039 'Content-Type': 'application/json',1040 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1041 }1042 let body = JSON.stringify({1043 replyToken: reply_token,1044 messages: [1045 {1046 type: "template",1047 altText: "This is a buttons template",1048 template: {1049 type: "buttons",1050 thumbnailImageUrl: "https://1.bp.blogspot.com/-U90M8DyKu7Q/W9EtONMCf6I/AAAAAAAAW_4/7L_jB_Rg9oweu2HKhULNdu9WNefw9zf9wCLcBGAs/s1600/sao-full.jpg",1051 imageAspectRatio: "rectangle",1052 imageSize: "cover",1053 imageBackgroundColor: "#FFFFFF",1054 title: "à¸à¸´à¸à¸à¹à¸à¹à¸à¹à¸²à¸«à¸à¹à¸²à¸à¸µà¹",1055 defaultAction: {1056 type: "uri",1057 label: "contact",1058 uri: "https://www.google.com"1059 },1060 actions: [1061 {1062 type: "text",1063 label: "à¸à¸µà¹à¸¡à¸¥à¸¥à¹",1064 text: "mrjourney.6012@gmail.com"1065 },1066 {1067 type: "postback",1068 label: "à¹à¸à¸´à¹à¸¡à¸¥à¸à¸£à¸à¹à¸à¹à¸",1069 data: "action=add&itemid=123"1070 },1071 {1072 type: "uri",1073 label: "à¸à¹à¸²à¸à¸£à¸²à¸¢à¸¥à¸°à¹à¸à¸µà¸¢à¸",1074 uri: "https://www.google.com"1075 }1076 ]1077 }1078 }1079 ]1080 })1081 request.post({1082 url: 'https://api.line.me/v2/bot/message/reply',1083 headers: headers,1084 body: body1085 }, (err, res, body) => {1086 console.log('status = ' + res.statusCode);1087 });1088}1089function replyRecommend(reply_token, msg) {1090 let headers = {1091 'Content-Type': 'application/json',1092 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1093 }1094 let body = JSON.stringify({1095 replyToken: reply_token,1096 messages: [1097 {1098 type: "text",1099 text: " à¹à¸à¸°à¸à¸³à¸à¸°à¹à¸£à¸à¸µ?",1100 quickReply: {1101 items: [1102 {1103 type: "action",1104 imageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601125619647eat.png?alt=media&token=61ebdb96-4649-406f-b7e1-e39e8730d909",1105 action: {1106 type: "message",1107 label: "à¸à¸µà¹à¸à¸´à¸",1108 text: "à¸à¸µà¹à¸à¸´à¸"1109 }1110 },1111 {1112 type: "action",1113 imageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601125559896place.png?alt=media&token=e2d872e8-6b87-443c-a88d-7bd8bf796009",1114 action: {1115 type: "message",1116 label: "à¸à¸µà¹à¹à¸à¸µà¹à¸¢à¸§",1117 text: "à¸à¸µà¹à¹à¸à¸µà¹à¸¢à¸§"1118 }1119 },1120 {1121 type: "action",1122 imageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601125494822sleep.png?alt=media&token=a33b0a23-a1bf-4768-b39e-2f13f0841cac",1123 action: {1124 type: "message",1125 label: "à¸à¸µà¹à¸à¸±à¸",1126 text: "à¸à¸µà¹à¸à¸±à¸"1127 }1128 }1129 ]1130 }1131 }1132 ]1133 })1134 request.post({1135 url: 'https://api.line.me/v2/bot/message/reply',1136 headers: headers,1137 body: body1138 }, (err, res, body) => {1139 console.log('status = ' + res.statusCode);1140 });1141}1142// function replyRecommendEat(reply_token, msg) {1143// let headers = {1144// 'Content-Type': 'application/json',1145// 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1146// }1147// let body = JSON.stringify({1148// replyToken: reply_token,1149// messages: [1150// {1151// type: "carousel",1152// contents: [1153// {1154// type: "bubble",1155// direction: "ltr",1156// hero: {1157// type: "image",1158// url: "https://food.mthai.com/app/uploads/2013/07/10.jpg",1159// size: "full",1160// aspectRatio: "16:9",1161// aspectMode: "cover"1162// },1163// body: {1164// type: "box",1165// layout: "vertical",1166// spacing: "sm",1167// contents: [1168// {1169// type: "text",1170// text: "สรà¹à¸²à¸à¹à¸à¸à¸à¸²à¸£à¸à¹à¸à¸à¹à¸à¸µà¹à¸¢à¸§",1171// weight: "bold",1172// size: "lg",1173// align: "center",1174// wrap: true,1175// contents: []1176// }1177// ]1178// },1179// footer: {1180// type: "box",1181// layout: "vertical",1182// spacing: "sm",1183// contents: [1184// {1185// type: "button",1186// action: {1187// type: "message",1188// label: "#สรà¹à¸²à¸à¸à¸£à¸´à¸",1189// text: "#สรà¹à¸²à¸à¸à¸£à¸´à¸"1190// },1191// color: "#F37945",1192// style: "primary"1193// }1194// ]1195// }1196// },1197// {1198// type: "bubble",1199// direction: "ltr",1200// hero: {1201// type: "image",1202// url: "https://food.mthai.com/app/uploads/2013/07/10.jpg",1203// size: "full",1204// aspectRatio: "16:9",1205// aspectMode: "cover"1206// },1207// body: {1208// type: "box",1209// layout: "vertical",1210// spacing: "sm",1211// contents: [1212// {1213// type: "text",1214// text: "วิà¸à¸µà¸à¸²à¸£à¹à¸à¹à¸à¸²à¸",1215// weight: "bold",1216// size: "lg",1217// align: "center",1218// wrap: true,1219// contents: []1220// }1221// ]1222// },1223// footer: {1224// type: "box",1225// layout: "vertical",1226// spacing: "sm",1227// contents: [1228// {1229// type: "button",1230// action: {1231// type: "message",1232// label: "#วิà¸à¸µà¸à¸²à¸£à¹à¸à¹",1233// text: "#วิà¸à¸µà¸à¸²à¸£à¹à¸à¹"1234// },1235// color: "#F37945",1236// style: "primary"1237// }1238// ]1239// }1240// },1241// {1242// type: "bubble",1243// direction: "ltr",1244// hero: {1245// type: "image",1246// url: "https://food.mthai.com/app/uploads/2013/07/10.jpg",1247// size: "full",1248// aspectRatio: "16:9",1249// aspectMode: "cover"1250// },1251// body: {1252// type: "box",1253// layout: "vertical",1254// spacing: "sm",1255// contents: [1256// {1257// type: "text",1258// text: "à¸à¸¹à¹à¸à¸à¸à¸²à¸£à¸à¹à¸à¸à¹à¸à¸µà¹à¸¢à¸§",1259// weight: "bold",1260// size: "lg",1261// align: "center",1262// wrap: true,1263// contents: []1264// }1265// ]1266// },1267// footer: {1268// type: "box",1269// layout: "vertical",1270// spacing: "sm",1271// contents: [1272// {1273// type: "button",1274// action: {1275// type: "message",1276// label: "#à¸à¸¹à¸à¸£à¸´à¸",1277// text: "#à¸à¸¹à¸à¸£à¸´à¸"1278// },1279// color: "#F37945",1280// style: "primary"1281// }1282// ]1283// }1284// },1285// {1286// type: "bubble",1287// direction: "ltr",1288// hero: {1289// type: "image",1290// url: "https://food.mthai.com/app/uploads/2013/07/10.jpg",1291// size: "full",1292// aspectRatio: "16:9",1293// aspectMode: "cover"1294// },1295// body: {1296// type: "box",1297// layout: "vertical",1298// spacing: "sm",1299// contents: [1300// {1301// type: "text",1302// text: "à¹à¸à¸°à¸à¸³à¸ªà¸à¸²à¸à¸à¸µà¹",1303// weight: "bold",1304// size: "lg",1305// align: "center",1306// wrap: true,1307// contents: []1308// }1309// ]1310// },1311// footer: {1312// type: "box",1313// layout: "vertical",1314// spacing: "sm",1315// contents: [1316// {1317// type: "button",1318// action: {1319// type: "message",1320// label: "#à¹à¸à¸°à¸à¸³",1321// text: "#à¹à¸à¸°à¸à¸³"1322// },1323// color: "#F37945",1324// style: "primary"1325// }1326// ]1327// }1328// }1329// ]1330// }1331// ]1332// })1333// request.post({1334// url: 'https://api.line.me/v2/bot/message/reply',1335// headers: headers,1336// body: body1337// }, (err, res, body) => {1338// console.log('status = ' + res.statusCode);1339// });1340// }1341function replyHelp(reply_token, msg) {1342 let headers = {1343 'Content-Type': 'application/json',1344 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1345 }1346 let body = JSON.stringify({1347 replyToken: reply_token,1348 messages: [1349 {1350 type: "text",1351 text: " à¸à¸¢à¸²à¸à¹à¸«à¹à¸à¹à¸§à¸¢à¹à¸£à¸·à¹à¸à¸à¸à¸°à¹à¸£à¸à¸µà¸à¸£à¸±à¸?",1352 quickReply: {1353 items: [1354 {1355 type: "action",1356 imageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601199781153Create.png?alt=media&token=388d4d44-fae8-497a-bf61-fc77c2ce46b3",1357 action: {1358 type: "message",1359 label: "สรà¹à¸²à¸à¸à¸£à¸´à¸",1360 text: "วิà¸à¸µà¸à¸²à¸£à¸ªà¸£à¹à¸²à¸à¸à¸£à¸´à¸"1361 }1362 },1363 {1364 type: "action",1365 imageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601199871983Check.png?alt=media&token=3f98d61f-eb10-4e7e-b88f-622e6e6768e0",1366 action: {1367 type: "message",1368 label: "à¸à¸¹à¹à¸à¸",1369 text: "วิà¸à¸µà¸à¸²à¸£à¸à¸¹à¹à¸à¸"1370 }1371 },1372 {1373 type: "action",1374 imageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601199904275Bill.png?alt=media&token=f9ef39dc-8344-4614-bcf4-6edf82926598",1375 action: {1376 type: "message",1377 label: "à¸à¸´à¸¥à¹à¸à¹à¸à¹à¸à¸´à¸",1378 text: "วิà¸à¸µà¸à¸²à¸£à¸à¸±à¸à¸à¸²à¸£à¸à¸´à¸¥"1379 }1380 }1381 ]1382 }1383 }1384 ]1385 })1386 request.post({1387 url: 'https://api.line.me/v2/bot/message/reply',1388 headers: headers,1389 body: body1390 }, (err, res, body) => {1391 console.log('status = ' + res.statusCode);1392 });1393}1394function replyHelpCreateTrip(reply_token, msg) {1395 let headers = {1396 'Content-Type': 'application/json',1397 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1398 }1399 let body = JSON.stringify({1400 replyToken: reply_token,1401 messages: [1402 {1403 type: "image",1404 originalContentUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601135456471menu-09.png?alt=media&token=8b978458-96c8-432c-a734-5e378bc5dc31",1405 previewImageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601135456471menu-09.png?alt=media&token=8b978458-96c8-432c-a734-5e378bc5dc31"1406 }1407 ]1408 })1409 request.post({1410 url: 'https://api.line.me/v2/bot/message/reply',1411 headers: headers,1412 body: body1413 }, (err, res, body) => {1414 console.log('status = ' + res.statusCode);1415 });1416}1417function replyHelpPlan(reply_token, msg) {1418 let headers = {1419 'Content-Type': 'application/json',1420 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1421 }1422 let body = JSON.stringify({1423 replyToken: reply_token,1424 messages: [1425 {1426 type: "image",1427 originalContentUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601135531375menu-10.png?alt=media&token=a57f9a3a-402d-4b89-bd9c-b068b17eb1c6",1428 previewImageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601135531375menu-10.png?alt=media&token=a57f9a3a-402d-4b89-bd9c-b068b17eb1c6"1429 }1430 ]1431 })1432 request.post({1433 url: 'https://api.line.me/v2/bot/message/reply',1434 headers: headers,1435 body: body1436 }, (err, res, body) => {1437 console.log('status = ' + res.statusCode);1438 });1439}1440function replyHelpBill(reply_token, msg) {1441 let headers = {1442 'Content-Type': 'application/json',1443 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1444 }1445 let body = JSON.stringify({1446 replyToken: reply_token,1447 messages: [1448 {1449 type: "image",1450 originalContentUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601135590386menu-11.png?alt=media&token=cb138a53-2c36-4aae-a2a4-d054d4d67e21",1451 previewImageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1601135590386menu-11.png?alt=media&token=cb138a53-2c36-4aae-a2a4-d054d4d67e21"1452 }1453 ]1454 })1455 request.post({1456 url: 'https://api.line.me/v2/bot/message/reply',1457 headers: headers,1458 body: body1459 }, (err, res, body) => {1460 console.log('status = ' + res.statusCode);1461 });1462}1463function replyDeleteTrip(reply_token, msg) {1464 let headers = {1465 'Content-Type': 'application/json',1466 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1467 }1468 let body = JSON.stringify({1469 replyToken: reply_token,1470 messages: [1471 {1472 type: 'text',1473 text: msg1474 },1475 {1476 type: "flex",1477 altText: "Flex Message",1478 contents: {1479 type: "bubble",1480 body: {1481 layout: "vertical",1482 contents: [1483 {1484 type: "text",1485 align: "center",1486 weight: "bold",1487 text: "à¸à¸£à¸´à¸à¸à¸¹à¸à¸¢à¸à¹à¸¥à¸´à¸à¸ªà¸³à¹à¸£à¹à¸ มาสรà¹à¸²à¸à¹à¸«à¸¡à¹à¸à¸±à¸à¹à¸à¸à¸°!"1488 }1489 ],1490 type: "box"1491 },1492 direction: "ltr",1493 footer: {1494 type: "box",1495 layout: "vertical",1496 contents: [1497 {1498 action: {1499 label: "สรà¹à¸²à¸à¸à¸£à¸´à¸",1500 type: "uri",1501 uri: "https://liff.line.me/1653975470-jV83lv9w"1502 },1503 type: "button",1504 color: "#C25738",1505 height: "sm",1506 margin: "xs",1507 style: "primary"1508 }1509 ]1510 }1511 }1512 }1513 ]1514 })1515 request.post({1516 url: 'https://api.line.me/v2/bot/message/reply',1517 headers: headers,1518 body: body1519 }, (err, res, body) => {1520 console.log('status = ' + res.statusCode);1521 });1522}1523function replyRating(reply_token, msg) {1524 let headers = {1525 'Content-Type': 'application/json',1526 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1527 }1528 let body = JSON.stringify({1529 replyToken: reply_token,1530 messages: [1531 {1532 type: 'text',1533 text: msg1534 },1535 {1536 type: "flex",1537 altText: "Flex Message",1538 contents: {1539 type: "bubble",1540 body: {1541 layout: "vertical",1542 contents: [1543 {1544 type: "text",1545 align: "center",1546 weight: "bold",1547 text: "มาà¹à¸«à¹à¸à¸°à¹à¸à¸à¸à¸±à¸à¹à¸à¸à¸°!"1548 }1549 ],1550 type: "box"1551 },1552 direction: "ltr",1553 footer: {1554 type: "box",1555 layout: "vertical",1556 contents: [1557 {1558 action: {1559 label: "à¹à¸«à¹à¸à¸°à¹à¸à¸",1560 type: "uri",1561 uri: "https://liff.line.me/1653975470-q8mJvPdV"1562 },1563 type: "button",1564 color: "#C25738",1565 height: "sm",1566 margin: "xs",1567 style: "primary"1568 }1569 ]1570 }1571 }1572 }1573 ]1574 })1575 request.post({1576 url: 'https://api.line.me/v2/bot/message/reply',1577 headers: headers,1578 body: body1579 }, (err, res, body) => {1580 console.log('status = ' + res.statusCode);1581 });1582}1583function replyRecommendEat(reply_token, locationEat) {1584 let contentShow = []1585 locationEat.map((u) => {1586 if (u.thumbnail_url === "") {1587 contentShow.push({1588 thumbnailImageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1605729496312plan-01.png?alt=media&token=2b1e04e9-33b6-49dd-b68f-e8ec2490b50c",1589 imageBackgroundColor: "#FFFFFF",1590 title: u.place_name,1591 text: u.category_description,1592 defaultAction: {1593 type: "uri",1594 label: "LINE",1595 uri: "https://www.google.com/maps"1596 },1597 actions: [1598 {1599 type: "uri",1600 label: "Google Map",1601 uri: "https://www.google.com/maps"1602 }1603 ]1604 })1605 } else {1606 contentShow.push({1607 thumbnailImageUrl: u.thumbnail_url,1608 imageBackgroundColor: "#FFFFFF",1609 title: u.place_name,1610 text: u.category_description,1611 defaultAction: {1612 type: "uri",1613 label: "LINE",1614 uri: "https://www.google.com/maps"1615 },1616 actions: [1617 {1618 type: "uri",1619 label: "Google Map",1620 uri: "https://www.google.com/maps"1621 }1622 ]1623 })1624 }1625 })1626 let headers = {1627 'Content-Type': 'application/json',1628 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1629 }1630 let body = JSON.stringify({1631 replyToken: reply_token,1632 messages: [1633 {1634 type: "template",1635 altText: "This is a carousel template",1636 template: {1637 type: "carousel",1638 imageAspectRatio: "rectangle",1639 imageSize: "cover",1640 columns: contentShow,1641 }1642 }1643 ]1644 })1645 request.post({1646 url: 'https://api.line.me/v2/bot/message/reply',1647 headers: headers,1648 body: body1649 }, (err, res, body) => {1650 console.log('status = ' + res.statusCode);1651 });1652}1653function replyRecommendTravel(reply_token, locationTravel) {1654 let contentShow = []1655 locationTravel.map((u) => {1656 if (u.thumbnail_url === "") {1657 contentShow.push({1658 thumbnailImageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1605729496312plan-01.png?alt=media&token=2b1e04e9-33b6-49dd-b68f-e8ec2490b50c",1659 imageBackgroundColor: "#FFFFFF",1660 title: u.place_name,1661 text: u.category_description,1662 defaultAction: {1663 type: "uri",1664 label: "LINE",1665 uri: "https://www.google.com/maps"1666 },1667 actions: [1668 {1669 type: "uri",1670 label: "Google Map",1671 uri: "https://www.google.com/maps"1672 }1673 ]1674 })1675 } else {1676 contentShow.push({1677 thumbnailImageUrl: u.thumbnail_url,1678 imageBackgroundColor: "#FFFFFF",1679 title: u.place_name,1680 text: u.category_description,1681 defaultAction: {1682 type: "uri",1683 label: "LINE",1684 uri: "https://www.google.com/maps"1685 },1686 actions: [1687 {1688 type: "uri",1689 label: "Google Map",1690 uri: "https://www.google.com/maps"1691 }1692 ]1693 })1694 }1695 })1696 let headers = {1697 'Content-Type': 'application/json',1698 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1699 }1700 let body = JSON.stringify({1701 replyToken: reply_token,1702 messages: [1703 {1704 type: "template",1705 altText: "This is a carousel template",1706 template: {1707 type: "carousel",1708 imageAspectRatio: "rectangle",1709 imageSize: "cover",1710 columns: contentShow,1711 }1712 }1713 ]1714 })1715 request.post({1716 url: 'https://api.line.me/v2/bot/message/reply',1717 headers: headers,1718 body: body1719 }, (err, res, body) => {1720 console.log('status = ' + res.statusCode);1721 });1722}1723function replyRecommendSleep(reply_token, locationSleep) {1724 let contentShow = []1725 locationSleep.map((u) => {1726 if (u.thumbnail_url === "") {1727 contentShow.push({1728 thumbnailImageUrl: "https://firebasestorage.googleapis.com/v0/b/test-storage-rom.appspot.com/o/1605729496312plan-01.png?alt=media&token=2b1e04e9-33b6-49dd-b68f-e8ec2490b50c",1729 imageBackgroundColor: "#FFFFFF",1730 title: u.place_name,1731 text: u.category_description,1732 defaultAction: {1733 type: "uri",1734 label: "LINE",1735 uri: "https://www.google.com/maps"1736 },1737 actions: [1738 {1739 type: "uri",1740 label: "Google Map",1741 uri: "https://www.google.com/maps"1742 }1743 ]1744 })1745 } else {1746 contentShow.push({1747 thumbnailImageUrl: u.thumbnail_url,1748 imageBackgroundColor: "#FFFFFF",1749 title: u.place_name,1750 text: u.category_description,1751 defaultAction: {1752 type: "uri",1753 label: "LINE",1754 uri: "https://www.google.com/maps"1755 },1756 actions: [1757 {1758 type: "uri",1759 label: "Google Map",1760 uri: "https://www.google.com/maps"1761 }1762 ]1763 })1764 }1765 })1766 let headers = {1767 'Content-Type': 'application/json',1768 'Authorization': 'Bearer {EUEqmnC5MpIHn7O3gS9uJ2AJBVt7JCotZj/+t2hOOlBTt7b/+4nPAg/9BFeRawRghXeIeqZe5EMVIexmmEh5c80nwP+BMli10YB6vNFLl38OHFljNNNy1jS9Ft52GmAIUro72i8ebhHfzD9mN9CX1QdB04t89/1O/w1cDnyilFU=}'1769 }1770 let body = JSON.stringify({1771 replyToken: reply_token,1772 messages: [1773 {1774 type: "template",1775 altText: "This is a carousel template",1776 template: {1777 type: "carousel",1778 imageAspectRatio: "rectangle",1779 imageSize: "cover",1780 columns: contentShow,1781 }1782 }1783 ]1784 })1785 request.post({1786 url: 'https://api.line.me/v2/bot/message/reply',1787 headers: headers,1788 body: body1789 }, (err, res, body) => {1790 console.log('status = ' + res.statusCode);1791 });1792}...
LineClient-reply.spec.js
Source:LineClient-reply.spec.js
1import MockAdapter from 'axios-mock-adapter';2import LineClient from '../LineClient';3const REPLY_TOKEN = 'nHuyWiB7yP5Zw52FIkcQobQuGDXCTA';4const ACCESS_TOKEN = '1234567890';5const CHANNEL_SECRET = 'so-secret';6const headers = {7 Authorization: `Bearer ${ACCESS_TOKEN}`,8};9const createMock = () => {10 const client = new LineClient(ACCESS_TOKEN, CHANNEL_SECRET);11 const mock = new MockAdapter(client.axios);12 return { client, mock };13};14describe('Reply Message', () => {15 describe('#replyRawBody', () => {16 it('should call reply api', async () => {17 const { client, mock } = createMock();18 const reply = {};19 mock20 .onPost('/v2/bot/message/reply', {21 replyToken: REPLY_TOKEN,22 messages: [{ type: 'text', text: 'Hello!' }],23 })24 .reply(200, reply, headers);25 const res = await client.replyRawBody({26 replyToken: REPLY_TOKEN,27 messages: [28 {29 type: 'text',30 text: 'Hello!',31 },32 ],33 });34 expect(res).toEqual(reply);35 });36 });37 describe('#reply', () => {38 it('should call reply api', async () => {39 const { client, mock } = createMock();40 const reply = {};41 mock42 .onPost('/v2/bot/message/reply', {43 replyToken: REPLY_TOKEN,44 messages: [{ type: 'text', text: 'Hello!' }],45 })46 .reply(200, reply, headers);47 const res = await client.reply(REPLY_TOKEN, [48 {49 type: 'text',50 text: 'Hello!',51 },52 ]);53 expect(res).toEqual(reply);54 });55 });56 describe('#replyText', () => {57 it('should call reply api', async () => {58 const { client, mock } = createMock();59 const reply = {};60 mock61 .onPost('/v2/bot/message/reply', {62 replyToken: REPLY_TOKEN,63 messages: [{ type: 'text', text: 'Hello!' }],64 })65 .reply(200, reply, headers);66 const res = await client.replyText(REPLY_TOKEN, 'Hello!');67 expect(res).toEqual(reply);68 });69 });70 describe('#replyImage', () => {71 it('should call reply api', async () => {72 const { client, mock } = createMock();73 const reply = {};74 mock75 .onPost('/v2/bot/message/reply', {76 replyToken: REPLY_TOKEN,77 messages: [78 {79 type: 'image',80 originalContentUrl: 'https://example.com/original.jpg',81 previewImageUrl: 'https://example.com/preview.jpg',82 },83 ],84 })85 .reply(200, reply, headers);86 const res = await client.replyImage(87 REPLY_TOKEN,88 'https://example.com/original.jpg',89 'https://example.com/preview.jpg'90 );91 expect(res).toEqual(reply);92 });93 it('should use contentUrl as fallback', async () => {94 const { client, mock } = createMock();95 const reply = {};96 mock97 .onPost('/v2/bot/message/reply', {98 replyToken: REPLY_TOKEN,99 messages: [100 {101 type: 'image',102 originalContentUrl: 'https://example.com/original.jpg',103 previewImageUrl: 'https://example.com/original.jpg',104 },105 ],106 })107 .reply(200, reply, headers);108 const res = await client.replyImage(109 REPLY_TOKEN,110 'https://example.com/original.jpg'111 );112 expect(res).toEqual(reply);113 });114 it('should call reply api with object image arg', async () => {115 const { client, mock } = createMock();116 const reply = {};117 mock118 .onPost('/v2/bot/message/reply', {119 replyToken: REPLY_TOKEN,120 messages: [121 {122 type: 'image',123 originalContentUrl: 'https://example.com/original.jpg',124 previewImageUrl: 'https://example.com/preview.jpg',125 },126 ],127 })128 .reply(200, reply, headers);129 const res = await client.replyImage(REPLY_TOKEN, {130 originalContentUrl: 'https://example.com/original.jpg',131 previewImageUrl: 'https://example.com/preview.jpg',132 });133 expect(res).toEqual(reply);134 });135 });136 describe('#replyVideo', () => {137 it('should call reply api', async () => {138 const { client, mock } = createMock();139 const reply = {};140 mock141 .onPost('/v2/bot/message/reply', {142 replyToken: REPLY_TOKEN,143 messages: [144 {145 type: 'video',146 originalContentUrl: 'https://example.com/original.mp4',147 previewImageUrl: 'https://example.com/preview.jpg',148 },149 ],150 })151 .reply(200, reply, headers);152 const res = await client.replyVideo(153 REPLY_TOKEN,154 'https://example.com/original.mp4',155 'https://example.com/preview.jpg'156 );157 expect(res).toEqual(reply);158 });159 it('should call reply api with object video arg', async () => {160 const { client, mock } = createMock();161 const reply = {};162 mock163 .onPost('/v2/bot/message/reply', {164 replyToken: REPLY_TOKEN,165 messages: [166 {167 type: 'video',168 originalContentUrl: 'https://example.com/original.mp4',169 previewImageUrl: 'https://example.com/preview.jpg',170 },171 ],172 })173 .reply(200, reply, headers);174 const res = await client.replyVideo(REPLY_TOKEN, {175 originalContentUrl: 'https://example.com/original.mp4',176 previewImageUrl: 'https://example.com/preview.jpg',177 });178 expect(res).toEqual(reply);179 });180 });181 describe('#replyAudio', () => {182 it('should call reply api', async () => {183 const { client, mock } = createMock();184 const reply = {};185 mock186 .onPost('/v2/bot/message/reply', {187 replyToken: REPLY_TOKEN,188 messages: [189 {190 type: 'audio',191 originalContentUrl: 'https://example.com/original.m4a',192 duration: 240000,193 },194 ],195 })196 .reply(200, reply, headers);197 const res = await client.replyAudio(198 REPLY_TOKEN,199 'https://example.com/original.m4a',200 240000201 );202 expect(res).toEqual(reply);203 });204 it('should call reply api with object audio arg', async () => {205 const { client, mock } = createMock();206 const reply = {};207 mock208 .onPost('/v2/bot/message/reply', {209 replyToken: REPLY_TOKEN,210 messages: [211 {212 type: 'audio',213 originalContentUrl: 'https://example.com/original.m4a',214 duration: 240000,215 },216 ],217 })218 .reply(200, reply, headers);219 const res = await client.replyAudio(REPLY_TOKEN, {220 originalContentUrl: 'https://example.com/original.m4a',221 duration: 240000,222 });223 expect(res).toEqual(reply);224 });225 });226 describe('#replyLocation', () => {227 it('should call reply api', async () => {228 const { client, mock } = createMock();229 const reply = {};230 mock231 .onPost('/v2/bot/message/reply', {232 replyToken: REPLY_TOKEN,233 messages: [234 {235 type: 'location',236 title: 'my location',237 address: 'ã150-0002 æ±äº¬é½æ¸è°·åºæ¸è°·ï¼ä¸ç®ï¼ï¼âï¼',238 latitude: 35.65910807942215,239 longitude: 139.70372892916203,240 },241 ],242 })243 .reply(200, reply, headers);244 const res = await client.replyLocation(REPLY_TOKEN, {245 title: 'my location',246 address: 'ã150-0002 æ±äº¬é½æ¸è°·åºæ¸è°·ï¼ä¸ç®ï¼ï¼âï¼',247 latitude: 35.65910807942215,248 longitude: 139.70372892916203,249 });250 expect(res).toEqual(reply);251 });252 });253 describe('#replySticker', () => {254 it('should call reply api', async () => {255 const { client, mock } = createMock();256 const reply = {};257 mock258 .onPost('/v2/bot/message/reply', {259 replyToken: REPLY_TOKEN,260 messages: [261 {262 type: 'sticker',263 packageId: '1',264 stickerId: '1',265 },266 ],267 })268 .reply(200, reply, headers);269 const res = await client.replySticker(REPLY_TOKEN, '1', '1');270 expect(res).toEqual(reply);271 });272 it('should call reply api with object sticker arg', async () => {273 const { client, mock } = createMock();274 const reply = {};275 mock276 .onPost('/v2/bot/message/reply', {277 replyToken: REPLY_TOKEN,278 messages: [279 {280 type: 'sticker',281 packageId: '1',282 stickerId: '1',283 },284 ],285 })286 .reply(200, reply, headers);287 const res = await client.replySticker(REPLY_TOKEN, {288 packageId: '1',289 stickerId: '1',290 });291 expect(res).toEqual(reply);292 });293 });294 describe('#replyImagemap', () => {295 it('should call reply api', async () => {296 const { client, mock } = createMock();297 const reply = {};298 mock299 .onPost('/v2/bot/message/reply', {300 replyToken: REPLY_TOKEN,301 messages: [302 {303 type: 'imagemap',304 baseUrl: 'https://example.com/bot/images/rm001',305 altText: 'this is an imagemap',306 baseSize: {307 height: 1040,308 width: 1040,309 },310 actions: [311 {312 type: 'uri',313 linkUri: 'https://example.com/',314 area: {315 x: 0,316 y: 0,317 width: 520,318 height: 1040,319 },320 },321 {322 type: 'message',323 text: 'hello',324 area: {325 x: 520,326 y: 0,327 width: 520,328 height: 1040,329 },330 },331 ],332 },333 ],334 })335 .reply(200, reply, headers);336 const res = await client.replyImagemap(337 REPLY_TOKEN,338 'this is an imagemap',339 {340 baseUrl: 'https://example.com/bot/images/rm001',341 baseHeight: 1040,342 baseWidth: 1040,343 actions: [344 {345 type: 'uri',346 linkUri: 'https://example.com/',347 area: {348 x: 0,349 y: 0,350 width: 520,351 height: 1040,352 },353 },354 {355 type: 'message',356 text: 'hello',357 area: {358 x: 520,359 y: 0,360 width: 520,361 height: 1040,362 },363 },364 ],365 }366 );367 expect(res).toEqual(reply);368 });369 it('should support baseSize argument', async () => {370 const { client, mock } = createMock();371 const reply = {};372 mock373 .onPost('/v2/bot/message/reply', {374 replyToken: REPLY_TOKEN,375 messages: [376 {377 type: 'imagemap',378 baseUrl: 'https://example.com/bot/images/rm001',379 altText: 'this is an imagemap',380 baseSize: {381 height: 1040,382 width: 1040,383 },384 actions: [385 {386 type: 'uri',387 linkUri: 'https://example.com/',388 area: {389 x: 0,390 y: 0,391 width: 520,392 height: 1040,393 },394 },395 {396 type: 'message',397 text: 'hello',398 area: {399 x: 520,400 y: 0,401 width: 520,402 height: 1040,403 },404 },405 ],406 },407 ],408 })409 .reply(200, reply, headers);410 const res = await client.replyImagemap(411 REPLY_TOKEN,412 'this is an imagemap',413 {414 baseUrl: 'https://example.com/bot/images/rm001',415 baseSize: {416 height: 1040,417 width: 1040,418 },419 actions: [420 {421 type: 'uri',422 linkUri: 'https://example.com/',423 area: {424 x: 0,425 y: 0,426 width: 520,427 height: 1040,428 },429 },430 {431 type: 'message',432 text: 'hello',433 area: {434 x: 520,435 y: 0,436 width: 520,437 height: 1040,438 },439 },440 ],441 }442 );443 expect(res).toEqual(reply);444 });445 });446 describe('#replyTemplate', () => {447 it('should call reply api', async () => {448 const { client, mock } = createMock();449 const reply = {};450 mock451 .onPost('/v2/bot/message/reply', {452 replyToken: REPLY_TOKEN,453 messages: [454 {455 type: 'template',456 altText: 'this is a template',457 template: {458 type: 'buttons',459 thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',460 title: 'Menu',461 text: 'Please select',462 actions: [463 {464 type: 'postback',465 label: 'Buy',466 data: 'action=buy&itemid=123',467 },468 {469 type: 'postback',470 label: 'Add to cart',471 data: 'action=add&itemid=123',472 },473 {474 type: 'uri',475 label: 'View detail',476 uri: 'http://example.com/page/123',477 },478 ],479 },480 },481 ],482 })483 .reply(200, reply, headers);484 const res = await client.replyTemplate(485 REPLY_TOKEN,486 'this is a template',487 {488 type: 'buttons',489 thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',490 title: 'Menu',491 text: 'Please select',492 actions: [493 {494 type: 'postback',495 label: 'Buy',496 data: 'action=buy&itemid=123',497 },498 {499 type: 'postback',500 label: 'Add to cart',501 data: 'action=add&itemid=123',502 },503 {504 type: 'uri',505 label: 'View detail',506 uri: 'http://example.com/page/123',507 },508 ],509 }510 );511 expect(res).toEqual(reply);512 });513 });514 describe('#replyButtonTemplate', () => {515 it('should call reply api', async () => {516 const { client, mock } = createMock();517 const reply = {};518 mock519 .onPost('/v2/bot/message/reply', {520 replyToken: REPLY_TOKEN,521 messages: [522 {523 type: 'template',524 altText: 'this is a template',525 template: {526 type: 'buttons',527 thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',528 imageAspectRatio: 'rectangle',529 imageSize: 'cover',530 imageBackgroundColor: '#FFFFFF',531 title: 'Menu',532 text: 'Please select',533 actions: [534 {535 type: 'postback',536 label: 'Buy',537 data: 'action=buy&itemid=123',538 },539 {540 type: 'postback',541 label: 'Add to cart',542 data: 'action=add&itemid=123',543 },544 {545 type: 'uri',546 label: 'View detail',547 uri: 'http://example.com/page/123',548 },549 ],550 },551 },552 ],553 })554 .reply(200, reply, headers);555 const res = await client.replyButtonTemplate(556 REPLY_TOKEN,557 'this is a template',558 {559 thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',560 imageAspectRatio: 'rectangle',561 imageSize: 'cover',562 imageBackgroundColor: '#FFFFFF',563 title: 'Menu',564 text: 'Please select',565 actions: [566 {567 type: 'postback',568 label: 'Buy',569 data: 'action=buy&itemid=123',570 },571 {572 type: 'postback',573 label: 'Add to cart',574 data: 'action=add&itemid=123',575 },576 {577 type: 'uri',578 label: 'View detail',579 uri: 'http://example.com/page/123',580 },581 ],582 }583 );584 expect(res).toEqual(reply);585 });586 it('should support replyButtonsTemplate alias', async () => {587 const { client, mock } = createMock();588 const reply = {};589 mock590 .onPost('/v2/bot/message/reply', {591 replyToken: REPLY_TOKEN,592 messages: [593 {594 type: 'template',595 altText: 'this is a template',596 template: {597 type: 'buttons',598 thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',599 imageAspectRatio: 'rectangle',600 imageSize: 'cover',601 imageBackgroundColor: '#FFFFFF',602 title: 'Menu',603 text: 'Please select',604 actions: [605 {606 type: 'postback',607 label: 'Buy',608 data: 'action=buy&itemid=123',609 },610 {611 type: 'postback',612 label: 'Add to cart',613 data: 'action=add&itemid=123',614 },615 {616 type: 'uri',617 label: 'View detail',618 uri: 'http://example.com/page/123',619 },620 ],621 },622 },623 ],624 })625 .reply(200, reply, headers);626 const res = await client.replyButtonsTemplate(627 REPLY_TOKEN,628 'this is a template',629 {630 thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',631 imageAspectRatio: 'rectangle',632 imageSize: 'cover',633 imageBackgroundColor: '#FFFFFF',634 title: 'Menu',635 text: 'Please select',636 actions: [637 {638 type: 'postback',639 label: 'Buy',640 data: 'action=buy&itemid=123',641 },642 {643 type: 'postback',644 label: 'Add to cart',645 data: 'action=add&itemid=123',646 },647 {648 type: 'uri',649 label: 'View detail',650 uri: 'http://example.com/page/123',651 },652 ],653 }654 );655 expect(res).toEqual(reply);656 });657 });658 describe('#replyConfirmTemplate', () => {659 it('should call reply api', async () => {660 const { client, mock } = createMock();661 const reply = {};662 mock663 .onPost('/v2/bot/message/reply', {664 replyToken: REPLY_TOKEN,665 messages: [666 {667 type: 'template',668 altText: 'this is a confirm template',669 template: {670 type: 'confirm',671 text: 'Are you sure?',672 actions: [673 {674 type: 'message',675 label: 'Yes',676 text: 'yes',677 },678 {679 type: 'message',680 label: 'No',681 text: 'no',682 },683 ],684 },685 },686 ],687 })688 .reply(200, reply, headers);689 const res = await client.replyConfirmTemplate(690 REPLY_TOKEN,691 'this is a confirm template',692 {693 text: 'Are you sure?',694 actions: [695 {696 type: 'message',697 label: 'Yes',698 text: 'yes',699 },700 {701 type: 'message',702 label: 'No',703 text: 'no',704 },705 ],706 }707 );708 expect(res).toEqual(reply);709 });710 });711 describe('#replyCarouselTemplate', () => {712 it('should call reply api', async () => {713 const { client, mock } = createMock();714 const reply = {};715 mock716 .onPost('/v2/bot/message/reply', {717 replyToken: REPLY_TOKEN,718 messages: [719 {720 type: 'template',721 altText: 'this is a carousel template',722 template: {723 type: 'carousel',724 imageAspectRatio: 'rectangle',725 imageSize: 'cover',726 columns: [727 {728 thumbnailImageUrl:729 'https://example.com/bot/images/item1.jpg',730 title: 'this is menu',731 text: 'description',732 actions: [733 {734 type: 'postback',735 label: 'Buy',736 data: 'action=buy&itemid=111',737 },738 {739 type: 'postback',740 label: 'Add to cart',741 data: 'action=add&itemid=111',742 },743 {744 type: 'uri',745 label: 'View detail',746 uri: 'http://example.com/page/111',747 },748 ],749 },750 {751 thumbnailImageUrl:752 'https://example.com/bot/images/item2.jpg',753 title: 'this is menu',754 text: 'description',755 actions: [756 {757 type: 'postback',758 label: 'Buy',759 data: 'action=buy&itemid=222',760 },761 {762 type: 'postback',763 label: 'Add to cart',764 data: 'action=add&itemid=222',765 },766 {767 type: 'uri',768 label: 'View detail',769 uri: 'http://example.com/page/222',770 },771 ],772 },773 ],774 },775 },776 ],777 })778 .reply(200, reply, headers);779 const res = await client.replyCarouselTemplate(780 REPLY_TOKEN,781 'this is a carousel template',782 [783 {784 thumbnailImageUrl: 'https://example.com/bot/images/item1.jpg',785 title: 'this is menu',786 text: 'description',787 actions: [788 {789 type: 'postback',790 label: 'Buy',791 data: 'action=buy&itemid=111',792 },793 {794 type: 'postback',795 label: 'Add to cart',796 data: 'action=add&itemid=111',797 },798 {799 type: 'uri',800 label: 'View detail',801 uri: 'http://example.com/page/111',802 },803 ],804 },805 {806 thumbnailImageUrl: 'https://example.com/bot/images/item2.jpg',807 title: 'this is menu',808 text: 'description',809 actions: [810 {811 type: 'postback',812 label: 'Buy',813 data: 'action=buy&itemid=222',814 },815 {816 type: 'postback',817 label: 'Add to cart',818 data: 'action=add&itemid=222',819 },820 {821 type: 'uri',822 label: 'View detail',823 uri: 'http://example.com/page/222',824 },825 ],826 },827 ],828 {829 imageAspectRatio: 'rectangle',830 imageSize: 'cover',831 }832 );833 expect(res).toEqual(reply);834 });835 it('should work without option', async () => {836 const { client, mock } = createMock();837 const reply = {};838 mock839 .onPost('/v2/bot/message/reply', {840 replyToken: REPLY_TOKEN,841 messages: [842 {843 type: 'template',844 altText: 'this is a carousel template',845 template: {846 type: 'carousel',847 columns: [848 {849 thumbnailImageUrl:850 'https://example.com/bot/images/item1.jpg',851 title: 'this is menu',852 text: 'description',853 actions: [854 {855 type: 'postback',856 label: 'Buy',857 data: 'action=buy&itemid=111',858 },859 {860 type: 'postback',861 label: 'Add to cart',862 data: 'action=add&itemid=111',863 },864 {865 type: 'uri',866 label: 'View detail',867 uri: 'http://example.com/page/111',868 },869 ],870 },871 {872 thumbnailImageUrl:873 'https://example.com/bot/images/item2.jpg',874 title: 'this is menu',875 text: 'description',876 actions: [877 {878 type: 'postback',879 label: 'Buy',880 data: 'action=buy&itemid=222',881 },882 {883 type: 'postback',884 label: 'Add to cart',885 data: 'action=add&itemid=222',886 },887 {888 type: 'uri',889 label: 'View detail',890 uri: 'http://example.com/page/222',891 },892 ],893 },894 ],895 },896 },897 ],898 })899 .reply(200, reply, headers);900 const res = await client.replyCarouselTemplate(901 REPLY_TOKEN,902 'this is a carousel template',903 [904 {905 thumbnailImageUrl: 'https://example.com/bot/images/item1.jpg',906 title: 'this is menu',907 text: 'description',908 actions: [909 {910 type: 'postback',911 label: 'Buy',912 data: 'action=buy&itemid=111',913 },914 {915 type: 'postback',916 label: 'Add to cart',917 data: 'action=add&itemid=111',918 },919 {920 type: 'uri',921 label: 'View detail',922 uri: 'http://example.com/page/111',923 },924 ],925 },926 {927 thumbnailImageUrl: 'https://example.com/bot/images/item2.jpg',928 title: 'this is menu',929 text: 'description',930 actions: [931 {932 type: 'postback',933 label: 'Buy',934 data: 'action=buy&itemid=222',935 },936 {937 type: 'postback',938 label: 'Add to cart',939 data: 'action=add&itemid=222',940 },941 {942 type: 'uri',943 label: 'View detail',944 uri: 'http://example.com/page/222',945 },946 ],947 },948 ]949 );950 expect(res).toEqual(reply);951 });952 });953 describe('#replyImageCarouselTemplate', () => {954 it('should call reply api', async () => {955 const { client, mock } = createMock();956 const reply = {};957 mock958 .onPost('/v2/bot/message/reply', {959 replyToken: REPLY_TOKEN,960 messages: [961 {962 type: 'template',963 altText: 'this is an image carousel template',964 template: {965 type: 'image_carousel',966 columns: [967 {968 imageUrl: 'https://example.com/bot/images/item1.jpg',969 action: {970 type: 'postback',971 label: 'Buy',972 data: 'action=buy&itemid=111',973 },974 },975 {976 imageUrl: 'https://example.com/bot/images/item2.jpg',977 action: {978 type: 'message',979 label: 'Yes',980 text: 'yes',981 },982 },983 {984 imageUrl: 'https://example.com/bot/images/item3.jpg',985 action: {986 type: 'uri',987 label: 'View detail',988 uri: 'http://example.com/page/222',989 },990 },991 ],992 },993 },994 ],995 })996 .reply(200, reply, headers);997 const res = await client.replyImageCarouselTemplate(998 REPLY_TOKEN,999 'this is an image carousel template',1000 [1001 {1002 imageUrl: 'https://example.com/bot/images/item1.jpg',1003 action: {1004 type: 'postback',1005 label: 'Buy',1006 data: 'action=buy&itemid=111',1007 },1008 },1009 {1010 imageUrl: 'https://example.com/bot/images/item2.jpg',1011 action: {1012 type: 'message',1013 label: 'Yes',1014 text: 'yes',1015 },1016 },1017 {1018 imageUrl: 'https://example.com/bot/images/item3.jpg',1019 action: {1020 type: 'uri',1021 label: 'View detail',1022 uri: 'http://example.com/page/222',1023 },1024 },1025 ]1026 );1027 expect(res).toEqual(reply);1028 });1029 });1030 describe('#replyFlex', () => {1031 it('should call reply api', async () => {1032 const { client, mock } = createMock();1033 const reply = {};1034 mock1035 .onPost('/v2/bot/message/reply', {1036 replyToken: REPLY_TOKEN,1037 messages: [1038 {1039 type: 'flex',1040 altText: 'this is a flex message',1041 contents: {1042 type: 'bubble',1043 header: {1044 type: 'box',1045 layout: 'vertical',1046 contents: [1047 {1048 type: 'text',1049 text: 'Header text',1050 },1051 ],1052 },1053 hero: {1054 type: 'image',1055 url: 'https://example.com/flex/images/image.jpg',1056 },1057 body: {1058 type: 'box',1059 layout: 'vertical',1060 contents: [1061 {1062 type: 'text',1063 text: 'Body text',1064 },1065 ],1066 },1067 footer: {1068 type: 'box',1069 layout: 'vertical',1070 contents: [1071 {1072 type: 'text',1073 text: 'Footer text',1074 },1075 ],1076 },1077 styles: {1078 comment: 'See the example of a bubble style object',1079 },1080 },1081 },1082 ],1083 })1084 .reply(200, reply, headers);1085 const res = await client.replyFlex(1086 REPLY_TOKEN,1087 'this is a flex message',1088 {1089 type: 'bubble',1090 header: {1091 type: 'box',1092 layout: 'vertical',1093 contents: [1094 {1095 type: 'text',1096 text: 'Header text',1097 },1098 ],1099 },1100 hero: {1101 type: 'image',1102 url: 'https://example.com/flex/images/image.jpg',1103 },1104 body: {1105 type: 'box',1106 layout: 'vertical',1107 contents: [1108 {1109 type: 'text',1110 text: 'Body text',1111 },1112 ],1113 },1114 footer: {1115 type: 'box',1116 layout: 'vertical',1117 contents: [1118 {1119 type: 'text',1120 text: 'Footer text',1121 },1122 ],1123 },1124 styles: {1125 comment: 'See the example of a bubble style object',1126 },1127 }1128 );1129 expect(res).toEqual(reply);1130 });1131 });...
local-storage.tentative.https.window.js
Source:local-storage.tentative.https.window.js
1// META: script=/common/get-host-info.sub.js2// META: script=/common/utils.js3// META: script=/common/dispatcher/dispatcher.js4// META: script=../credentialless/resources/common.js5// META: script=./resources/common.js6const same_origin = get_host_info().HTTPS_ORIGIN;7const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;8const local_storage_key = "coep_credentialless_iframe_local_storage";9const local_storage_same_origin = "same_origin";10const local_storage_cross_origin = "cross_origin";11promise_test_parallel(async test => {12 // Add an item in the localStorage on same_origin.13 localStorage.setItem(local_storage_key, local_storage_same_origin);14 // Add an item in the localStorage on cross_origin.15 {16 const w_token = token();17 const w_url = cross_origin + executor_path + `&uuid=${w_token}`;18 const w = window.open(w_url);19 const reply_token = token();20 send(w_token, `21 localStorage.setItem("${local_storage_key}",22 "${local_storage_cross_origin}");23 send("${reply_token}", "done");24 `);25 assert_equals(await receive(reply_token), "done");26 w.close();27 }28 promise_test_parallel(async test => {29 let iframe = newAnonymousIframe(same_origin);30 let reply_token = token();31 send(iframe, `32 let value = localStorage.getItem("${local_storage_key}");33 send("${reply_token}", value);34 `)35 assert_equals(await receive(reply_token), "")36 }, "same_origin anonymous iframe can't access the localStorage");37 promise_test_parallel(async test => {38 let iframe = newAnonymousIframe(cross_origin);39 let reply_token = token();40 send(iframe, `41 let value = localStorage.getItem("${local_storage_key}");42 send("${reply_token}", value);43 `)44 assert_equals(await receive(reply_token), "")45 }, "cross_origin anonymous iframe can't access the localStorage");...
Using AI Code Generation
1const reply_token = require('wptelegram').reply_token;2const send_message = require('wptelegram').send_message;3const get_chat_id = require('wptelegram').get_chat_id;4const get_chat_username = require('wptelegram').get_chat_username;5const get_chat_title = require('wptelegram').get_chat_title;6const get_chat_type = require('wptelegram').get_chat_type;7const get_chat_all = require('wptelegram').get_chat_all;8const get_user_id = require('wptelegram').get_user_id;9const get_user_name = require('wptelegram').get_user_name;10const get_user_username = require('wptelegram').get_user_username;11const get_user_all = require('wptelegram').get_user_all;12const get_message_id = require('wptelegram').get_message_id;13const get_message_text = require('wptelegram').get_message_text;14const get_message_date = require('wptelegram').get_message_date;15const get_message_all = require('wptelegram').get_message_all;16const get_file_id = require('wptelegram').get_file_id;17const get_file_unique_id = require('wptelegram').get_file_unique_id;
Using AI Code Generation
1const token = process.env.WPTELEGRAM_TOKEN;2const wptelegram = require('wptelegram');3const wptelegramBot = wptelegram(token);4const bot = wptelegramBot.bot;5bot.onText(/\/start/, (msg) => {6 bot.sendMessage(msg.chat.id, 'Hello World');7});8bot.on('message', (msg) => {9 console.log(msg);10 var chatId = msg.chat.id;11 var replyToken = msg.reply_token;12 if (msg.text.match(/\/start/)) {13 bot.sendMessage(chatId, 'Hello World');14 } else if (msg.text.match(/\/reply/)) {15 bot.sendMessage(chatId, 'Hello World', {16 });17 } else if (msg.text.match(/\/reply_token/)) {18 bot.sendMessage(chatId, 'Hello World', {19 });20 }21});22bot.on('callback_query', (msg) => {23 var chatId = msg.chat.id;24 var replyToken = msg.reply_token;25 if (msg.text.match(/\/start/)) {26 bot.sendMessage(chatId, 'Hello World');27 } e
Using AI Code Generation
1const wptelegram = require('wptelegram')2exports.handler = function (event, context, callback) {3 wptelegram.reply_token(reply_token, message).then((res) => {4 callback(null, {5 body: JSON.stringify(res)6 })7 }).catch(err => {8 callback(null, {9 body: JSON.stringify(err)10 })11 })12}
Using AI Code Generation
1const wptelegram = require('wptelegram');2const wp = new wptelegram('your_bot_token');3wp.sendMessage('chat_id', 'message_text');4const wptelegram = require('wptelegram');5const wp = new wptelegram('your_bot_token');6wp.sendMessage('-100123456789', 'message_text');7const wptelegram = require('wptelegram');8const wp = new wptelegram('your_bot_token');9wp.sendMessage('-123456789', 'message_text');10const wptelegram = require('wptelegram');11const wp = new wptelegram('your_bot_token');12wp.reply_keyboard = true;13wp.reply_keyboard_markup = {14};15wp.sendMessage('chat_id', 'message_text');16const wptelegram = require('wptelegram');17const wp = new wptelegram('your_bot_token');18wp.reply_keyboard = true;19wp.reply_keyboard_markup = {20};21wp.sendMessage('chat_id', 'message_text');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!