Coder Social home page Coder Social logo

line_bot_tensou's Introduction

LINE_BOT_TENSOU

LINEボットでチャット内容をメールに転送する

↑この記事からの変更点を以降に記載する。

重要な定義をプロジェクトのプロパティで保持するように変更した

LINEボットのチャンネルアクセストークンは、プロジェクトのプロパティCHANNEL_ACCESS_TOKENで定義する。

LINEボット転送ちゃんネル.gs の以下のコードで読み込んで使用される。

const CHANNEL_ACCESS_TOKEN = PropertiesService.getScriptProperties().getProperty('CHANNEL_ACCESS_TOKEN');

名簿のスプレッドシートIDは、プロジェクトのプロパティMEMBER_SPREADSHEET_IDで定義する。 名簿のシート名は、プロジェクトのプロパティMEMBER_SHEET_NAMEで定義する。

名簿スプレッドシート.gs の以下のコードで読み込んで使用される。

// スプレッドシートのURLは
// https://docs.google.com/spreadsheets/d/XXXXXXX/edit
// のような形になっています。XXXXXXXの部分がIDになります。
// 「グループ名簿」のスプレッドシート
const MEMBER_SPREADSHEET_ID = PropertiesService.getScriptProperties().getProperty('MEMBER_SPREADSHEET_ID');
const MEMBER_SHEET_NAME = PropertiesService.getScriptProperties().getProperty('MEMBER_SHEET_NAME');

ログスプレッドシートIDは、プロジェクトのプロパティRICHMENUS_SPREADSHEET_IDで定義する。 ログのシート名は、コード上で「ログ」に固定している。

log.gsの以下のコードで読み込んで使用される。

const LOG_SPREADSHEET_ID = PropertiesService.getScriptProperties().getProperty('RICHMENUS_SPREADSHEET_ID');

名簿スプレッドシート用のクラスを用意した

名簿スプレッドシート.gs の以下のコードは、名簿の各列を表しており、LINEボット転送メールアドレスが17列目(this.lineBotTransferEMail)になっている。

  let TobaMember = function(record) {
    [this.name,
    this.birthday,
    this.age,
    this.licenseDeadline,
    this.smartPhoneEMail,
    this.homeEMail,
    this.smartPhoneNumber,
    this.officeEMail,
    this.homePhoneNumber,
    this.officePhoneNumber,
    this.officeName,
    this.officePostalCode,
    this.officeAddress,
    this.homePostalCode,
    this.homeAddress,
    this.bloodType,
    this.lineBotTransferEMail] = record;
  };

記事の様な、1列しかないスプレッドシートで使う場合は、以下のコードに修正するとよい(と思う)。

  let TobaMember = function(record) {
    [this.lineBotTransferEMail] = record;
  };

転送する際に、宛先一人ずつメールを送っていたが、どうせお互いにアドレス知っているので、まとめて一通のメールで送るように変更した。

  1. まとめて一通のメールで送る場合は、utilities.gs sendEmail() を使用する。
  2. 個別にメールを送る場合は、utilities.gs sendEmailIndividually() を使用する。

メッセージTextと、静止画imageを転送するようにした。

  1. JSON.parse(e.postData.contents).events[0].message.type が image と text のみ処理する。
  2. メール添付ファイルの制限など未調査なので、サイズの大きい画像が送れるか不明。
  3. events[0]しか処理していないので、複数来るケースがあれば後続のデータは無視する。 (複数の静止画をまとめ送るなどしたらこのケースになるかもしれない。その場合は最初の一枚しか転送しないと思われる。)

line_bot_tensou's People

Contributors

igapon50 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.