-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d211b55
commit 6bc91a9
Showing
7 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import axios from 'axios' | ||
import Actions from '../services/Actions.js' | ||
import logger from '../utils/logger.js' | ||
import { | ||
ITEM_ID, | ||
ITEM_NAME, | ||
CAT_ATTR_TAG_RELATIONS, | ||
STRAPI_TOURISM_TOKEN, | ||
} from '../utils/constants.js' | ||
const action = new Actions() | ||
const TOURISM_STRAPI_URL = process.env.TOURISM_STRAPI_URL || '' | ||
export const cancelBookingController = async (req, res) => { | ||
try { | ||
const { recipientNumber, messageBody, orderId } = req.body | ||
console.log(orderId) | ||
const getOrderFulfillmentDetails = await axios.get( | ||
`${TOURISM_STRAPI_URL}/order-fulfillments?order_id=${orderId}`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${STRAPI_TOURISM_TOKEN}`, | ||
}, | ||
} | ||
) | ||
if (getOrderFulfillmentDetails.data.data.length) { | ||
await axios.put( | ||
`${TOURISM_STRAPI_URL}/order-fulfillments/${getOrderFulfillmentDetails.data.data[0].id}`, | ||
{ | ||
data: { | ||
state_code: 'CANCELLED', | ||
state_value: 'CANCELLED BY HOTEL', | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${STRAPI_TOURISM_TOKEN}`, | ||
}, | ||
} | ||
) | ||
|
||
await action.send_message(recipientNumber, messageBody) | ||
return res.send({ message: 'Notified' }) | ||
} | ||
|
||
return res.send({ message: 'Cancel Booking Failed' }) | ||
} catch (error) { | ||
logger.error(error.message) | ||
return res.send({ message: error.message }) | ||
} | ||
} | ||
|
||
export const updateCatalog = async (req, res) => { | ||
try { | ||
await axios.put( | ||
`${TOURISM_STRAPI_URL}/items/${ITEM_ID}`, | ||
{ | ||
data: { | ||
name: ITEM_NAME, | ||
cat_attr_tag_relations: CAT_ATTR_TAG_RELATIONS, | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${STRAPI_TOURISM_TOKEN}`, | ||
}, | ||
} | ||
) | ||
|
||
return res.send({ message: 'Catalog Updated' }) | ||
} catch (error) { | ||
logger.error(error.message) | ||
return res.send({ message: error.message }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Actions from '../services/Actions.js' | ||
import logger from '../utils/logger.js' | ||
const action = new Actions() | ||
export const notificationController = async (req, res) => { | ||
try { | ||
const { recipientNumber, messageBody } = req.body | ||
const sendWhatsappNotificationResponse = await action.send_message( | ||
recipientNumber, | ||
messageBody | ||
) | ||
return res.send(sendWhatsappNotificationResponse) | ||
} catch (error) { | ||
logger.error(error.message) | ||
return res.send({ message: error.message }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import logger from '../utils/logger.js' | ||
import Twilio from 'twilio' | ||
const TWILIO_NUMBER = process.env.TWILIO_NUMBER | ||
const TWILIO_AUTH_TOKEN = process.env.TWILIO_AUTH_TOKEN | ||
const TWILIO_ACCOUNT_SID = process.env.TWILIO_ACCOUNT_SID | ||
|
||
const client = Twilio(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) | ||
|
||
export const sendWhatsappNotification = async ( | ||
recipientNumber, | ||
messageBody | ||
) => { | ||
try { | ||
const data = await client.messages.create({ | ||
body: messageBody, | ||
from: `whatsapp:${TWILIO_NUMBER}`, | ||
to: `whatsapp:${recipientNumber}`, | ||
}) | ||
|
||
const status = await client.messages(data.sid).fetch() | ||
console.log('data===>', data) | ||
console.log('status===>', status) | ||
if(status?.status!=="failed"){ | ||
return {message:'Notification Sent'} | ||
}return {message:'Failed to Send Notification'} | ||
} catch (error) { | ||
logger.error(error.message) | ||
throw new Error(error.message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const STRAPI_TOURISM_TOKEN = | ||
'82ed7f48afbd0c0605ef36bf4b81259f90c7e6bc357db032a011b1c0ab2bc7db2a753fa84c959f403b256ee66b44174dcc453bd0a40797ce8c22c1b6dab7f416cf3b8a247c19144bc3d019f229612f36b12612223b35f28a1a7fec6ff779228730b45fd93a793399d8f462ba0bada15077725a843d3023cf133838876da3547e' | ||
|
||
export const ITEM_ID = '2' | ||
export const ITEM_NAME = 'MUSEUM' | ||
|
||
export const CAT_ATTR_TAG_RELATIONS = [2, 3, 4, 5] |