summaryrefslogtreecommitdiff
path: root/server/controllers/message.js
blob: 37de7d20c368692e3dc7550bc764a4989e0f6c9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import generateOTP from '../utils/otp';
import sendSMS from '../services/twilio';

const sendOTP = async (req, res) => {
  const {mobile} = req.body;

  try {
    const otp = generateOTP();
    const message = `Your OTP for Aadhaar verification is : ${otp}`;
    sendSMS(mobile, message);
    res.status(200).json({message: 'OTP sent successfully', otpCode: otp});
  } catch (error) {
    res.status(404).json({message: error});
  }
};

const sendMessage = async (req, res) => {
  const {mobile, id} = req.body;

  try {
    const message = `Your request for aadhaar card has been successfully submitted. Please use the id: ${id} for future reference.`;
    sendSMS(mobile, message);
    res.status(200).json({message: 'Message sent successfully'});
  } catch (error) {
    res.status(404).json({message: error});
  }
};

export default {sendOTP, sendMessage};