{"size": 1063, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "kenta-ja8/line-notification-gcp-functions", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "index.js", "max_issues_repo_name": "kenta-ja8/line-notification-gcp-functions", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "index.js", "max_forks_repo_name": "kenta-ja8/line-notification-gcp-functions", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.3714285714, "max_line_length": 90, "alphanum_fraction": 0.6030103481}
const axiosBase = require('axios');

/**
 * Responds to any HTTP request.
 *
 * @param {!express:Request} req HTTP request context.
 * @param {!express:Response} res HTTP response context.
 */
exports.functionMain = async (req, res) => {
    
    await this.notifyLine(req);
    res.status(200).send(req.body);
  };

exports.notifyLine = async (req) => {
    const {mainMessage, from} = req.body
    try{
        const lineToken = process.env.LINE_TOKEN
        const axios = axiosBase.create({
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Authorization': `Bearer ${lineToken}`
          }
        });
        const params = new URLSearchParams();
        const fromMessage = from ? ` (from: ${from})` : '';
        params.append('message', `${mainMessage}${fromMessage}`);
        const response = await axios.post('https://notify-api.line.me/api/notify', params)
        console.log('request success: ', response.data)

    }catch(error){
        console.log('request error: ', error.response.data)
    }
}
