Way to send "Inbox" message via some API?

Hello! What I’m saying is going to be very ambitious and probably requires alot of time to nail correctly so just a word of warning!

I am trying to see if there is anyway to use some API (in or out of ROBLOX) to send a message to the user’s INBOX (not in-game chat, not the friends chat.) I am trying to figure and lay my options out to see if I can do this in ROBLOX alone, or will I have to use a third party API call, preferably one I made myself using python and/or JavaScript.

I have a WIP that I have that used HttpService and MessagingService. (with the help of chatgpt :P)
I’m almost confident we went the wrong way with this one, but I’m not certain as I am not a big fan of HttpService.

local HttpService = game:GetService('HttpService')
local MessagingService = game:GetService('MessagingService')

local function handleMessageRequest(reqBody)
	local userId = reqBody.userId

	-- Send a message to the user's inbox based on the UserId
	local success, message = pcall(function()
		local recipient = 'rbxuser://' .. userId
		local subject = 'Message from Roblox'
		local body = 'This is a test message from your Roblox game.'

		MessagingService:SendMessageAsync(recipient, subject, body)
	end)

	if success then
		return 'Message sent successfully!'
	else
		return 'Error sending the message: ' .. message
	end
end

-- Create an HTTP endpoint within the same script
local function handleHttpRequest(req, res)
	if req.Method == 'POST' and req.Path == '/send-message' then
		local success, request = pcall(function()
			return HttpService:JSONDecode(req.Body)
		end)

		if success and request.userId then
			res.Body = handleMessageRequest(request)
			res.StatusCode = 200
		else
			res.StatusCode = 400
		end
	else
		res.StatusCode = 404
	end

	res:Send()
end

-- Start the HTTP server
local server = game:GetService('HttpService'):CreateServer('127.0.0.1', 3000, handleHttpRequest) -- error happens here lol
server:Start()

If you’re able to understand what I’m saying and are able to help out, it would be really nice!
As always, any help possible is very appreciated!

You shouldn’t use ChatGPT considering the code it generated is using methods and API calls that don’t exist. But yes, you would use HttpService and an external server to handle the request.

I am not familiar with the Roblox WebAPI because I don’t often use it, however, you’d likely want to use this endpoint

3 Likes

That helped alot!
I managed to program my sending function and web server, but now I’m getting hit with a 401 (Unauthorized) error and I dont know how to fix it.
I’m trying to find some sort of documentation about a key/token but I can’t find it.