Skip to content

AdnanTech

Programming tutorials

  • Python
  • PHP
    • Laravel
    • WordPress
  • Javascript
    • React JS
    • Node.js
    • Vue JS
  • Databases
    • MySQL
    • MongoDB
  • Mobile apps
    • Android
    • iOS
  • Tutorials
    • Ticketing system
    • Chat app
  • Blog
  • Projects
  • API
    • Social network API
  • Services
    • Hash Generator
    • World Clock
    • Word Counter
    • Currency Converter
    • Financial Ledger
    • Time Difference
    • Stopwatch & Timer
    • Google Maps
  • SAAS
    • Job Entry

Messages

We have 2 APIs for messages. One for sending the message and one for retrieving the messages.

  • Send message
  • Fetch messages

Send message

Sends a message to the user if the user_id is provided. Otherwise, it will send the message to the admin. You can also send attachments with your message and they will be stored in private storage. Only you and the recipient can view the attachments.

It does not require you 2 to be friends. You can chat with anyone in the social network without being friends. The other user will receive a notification of new message.

URL = http://localhost:8000/api/messages/send

Method = POST

Headers

Acceptapplication/json
AuthorizationBearer {access_token}

Parameters

KeyTypeRequired
messagestringNo
user_idintegerNo
time_zonestring (e.g. Asia/Karachi)No
attachments[]files(s)No
  • message: The message can be empty in case if user wants to send only the attachments.
  • user_id: Tells the user whom you want to send a message. If the “user_id” is not specified, then the message will be sent to the admin.
  • attachments[]: It will be an array of attachments. All files will be saved in private storage.

Response

Status = 200

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
    "status": "success",
    "message": "Message has been sent.",
    "message_obj": {
        "id": 5,
        "message": "Hi",
        "sender_id": 2,
        "receiver_id": 3,
        "attachments": [
            "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ..."
        ],
        "created_at": "05 Oct, 2024 10:38:44 pm",
        "updated_at": "05 Oct, 2024 10:38:44 pm"
    }
}
  • attachments: It will be an array containing complete base64 string of attached files.

Since message attachments are being stored in private storage, so we are returning base64 string of file content instead of absolute path.

Fetch messages

Returns your chat with the user (if user_id is provided) or with admin (otherwise). It will also return attachments of each message (if any). The attachments will be in base64 string. Since we are saving attachments in private storage, that’s why generating a relative path will be in-secure.

URL = http://localhost:8000/api/messages/fetch

Method = POST

Headers

Acceptapplication/json
AuthorizationBearer {access_token}

Parameters

KeyTypeRequired
pageinteger (e.g. 1)Yes
user_idintegerNo
time_zonestring (e.g. Asia/Karachi)No
  • user_id: Tells the user of whom chat you want to fetch. If the “user_id” is not specified, then your chat with the admin will be returned.

Response

Status = 200

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
    "status": "success",
    "message": "Data has been fetched.",
    "messages": [
        {
            "id": 6,
            "message": "Hi",
            "sender_id": 2,
            "receiver_id": 3,
            "attachments": [
                {
                    "path": "data:image/jpeg;base64,/9j/4AAQSkZJRgAB...",
                    "name": "428672394.jpg",
                    "type": "image/jpeg"
                }
            ],
            "created_at": "05 Oct, 2024 10:40:15 pm"
        }
    ],
    "notifications_count": 0
}
previous next

Recent Posts

  • Soft Delete 🗑 – Node.js, MongoDB
  • 2 ways to loop through a number in React
  • Get updated value from Child to Parent – React
  • Next and previous links in PHP, MySQL
  • Case-sensitive search in MySQL

Recent Comments

  1. canada pharmaceuticals online generic on PDF view in browser and export as file – PHP
  2. System on (no title)
  3. adnanafzal565 on (no title)
  4. adnanafzal565 on (no title)
  5. System on (no title)

Archives

  • March 2025
  • February 2025
  • January 2025
  • November 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • November 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020

Categories

  • Android
  • Complete Projects
  • CSS
  • FFmpeg
  • Git
  • htaccess
  • HTML
  • iOS
  • Javascript
  • Laravel
  • Leap Motion Controller
  • MEVN
  • MongoDB
  • MySQL
  • Node.js
  • PHP
  • Python
  • React JS
  • Swift
  • Tips & Tricks
  • Uncategorized
  • Vue JS
  • WordPress
2019-2025
support@adnan-tech.com