Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- twilioClient.chat.services(TWILIO_CHAT_SERVICE_SID)
- .channels(req.params.id)
- .messages
- .list({
- pageSize: 2,
- page: 2
- }, (error, messages) => {
- if (error) {
- return res.status(error.status).json({
- message: 'Problem in getting messages',
- error: error
- });
- }
- if (Utility.isEmptyObject(messages)) {
- return res.status(404).send('Messages not found');
- }
- res.status(200).json({
- message: 'Messages retrieved sucessfully',
- docs: messages
- });
- });
- let limitCount = parseInt(req.query.limit > 0 ? req.query.limit : 10); // limitValue
- let pageNo = parseInt(req.query.pageNo > 0 ? req.query.pageNo : 0);
- let options = {
- method: 'GET',
- url: 'https://chat.twilio.com/v2/Services/IS/Channels/' +
- 'CH2f/Messages?Page=' + pageNo + '&PageSize=' + limitCount,
- headers:
- {
- 'cache-control': 'no-cache',
- Authorization: 'Basic QUNkZmQ0ZTQ1MTNiZGc3NTFjZTRlNmFiNDBiN2YzZWMxNw=='
- }
- };
- request(options, function (error, response, body) {
- console.log(body);
- if (error) {
- //console.error("There was an error loading the channels.", error);
- return res.status(error.status).json({
- message: 'Problem in getting messages',
- error: error
- });
- }
- if (Utility.isEmptyObject(response)) {
- return res.status(404).send('Messages not found');
- }
- res.status(200).json({
- status: 'Messages retrieved sucessfully',
- messages: JSON.parse(body)
- });
- });
Add Comment
Please, Sign In to add comment