Guest User

Untitled

a guest
Jan 18th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. twilioClient.chat.services(TWILIO_CHAT_SERVICE_SID)
  2. .channels(req.params.id)
  3. .messages
  4. .list({
  5. pageSize: 2,
  6. page: 2
  7. }, (error, messages) => {
  8. if (error) {
  9. return res.status(error.status).json({
  10. message: 'Problem in getting messages',
  11. error: error
  12. });
  13. }
  14.  
  15. if (Utility.isEmptyObject(messages)) {
  16. return res.status(404).send('Messages not found');
  17. }
  18.  
  19. res.status(200).json({
  20. message: 'Messages retrieved sucessfully',
  21. docs: messages
  22. });
  23. });
  24.  
  25. let limitCount = parseInt(req.query.limit > 0 ? req.query.limit : 10); // limitValue
  26. let pageNo = parseInt(req.query.pageNo > 0 ? req.query.pageNo : 0);
  27.  
  28. let options = {
  29. method: 'GET',
  30. url: 'https://chat.twilio.com/v2/Services/IS/Channels/' +
  31. 'CH2f/Messages?Page=' + pageNo + '&PageSize=' + limitCount,
  32. headers:
  33. {
  34. 'cache-control': 'no-cache',
  35. Authorization: 'Basic QUNkZmQ0ZTQ1MTNiZGc3NTFjZTRlNmFiNDBiN2YzZWMxNw=='
  36. }
  37. };
  38.  
  39. request(options, function (error, response, body) {
  40.  
  41. console.log(body);
  42.  
  43. if (error) {
  44. //console.error("There was an error loading the channels.", error);
  45. return res.status(error.status).json({
  46. message: 'Problem in getting messages',
  47. error: error
  48. });
  49. }
  50.  
  51. if (Utility.isEmptyObject(response)) {
  52. return res.status(404).send('Messages not found');
  53. }
  54.  
  55. res.status(200).json({
  56. status: 'Messages retrieved sucessfully',
  57. messages: JSON.parse(body)
  58. });
  59. });
Add Comment
Please, Sign In to add comment