Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Chatting with Japanese using Firebase Extensions

Chatting with Japanese using Firebase Extensions

Get to know how to build Translator Chatbot in LINE using Firebase Extensions

Firebase Thailand

November 09, 2019
Tweet

More Decks by Firebase Thailand

Other Decks in Technology

Transcript

  1. GDG Thailand Firebase Thailand Organized by Chatting with Japanese using

    Firebase Extensions Firebase Extensionsを使用して日本人とチャットする Warit Wanwithu LINE Thailand
  2. #FirebaseDevDay ❤ 0. Install Translation extension 1. Create LINE Chatbot

    2. Handle LINE Webhook using Cloud Functions and save to Firestore 3. Listen to Firestore trigger and push message back to LINE group
  3. #FirebaseDevDay { "destination": "xxxxxxxxxx", "events": [{ "replyToken": "0f3779fba3b349968c5d07db31eab56f", "type": "message",

    "timestamp": 1462629479859, "source": { "type": "user", "userId": "U4af4980629..." }, "message": { "id": "325708", "type": "text", "text": "Hello" } }]} 2. Handle LINE Webhook
  4. #FirebaseDevDay exports.LineWebhook = functions.region(region).runWith(runtimeOpts) .https.onRequest(async (req, res) => { let

    event = req.body.events[0]; if (event.message.type === 'text') { let input = event.message.text; await admin.firestore().collection('translations').doc('inputText') .set({ input: input }); } return res.status(200).send(req.method);; });
  5. #FirebaseDevDay exports.LineBotPush = functions.region(region).runWith(runtimeOpts) .firestore.document('translations/inputText').onWrite(async (change, context) => { let

    latest = change.after.data(); let input = latest.input; let containsJapanese = input.match(/[\u3000-\u303f\u3040-...]/); if (containsJapanese) { push(GROUP_ID, latest.translated.th); } else { push(GROUP_ID, latest.translated.ja); } });