Chat with trpc / nextjs / vercel

Hello, I would like to make a messaging system with trpc and nextjs. I host everything on Vercel so I need it to work in serverless. https://trpc.io/docs/subscriptions Is it possible to use this with upstash for example? Thanks
10 Replies
Neto
Neto•2y ago
with vercel you won't be able to create a chat-like feature
nexxel
nexxel•2y ago
you can use a websockets provider like pusher
Meyer
MeyerOP•2y ago
This is what I understood with all my research ( even using services like Pusher, Ably etc it is still not adapted with TRPC ) 😦 Ah, but Pusher and TRPC don't work, do they?
Neto
Neto•2y ago
you can send messages to trpc, and from there you send to pusher and listen to the messages on the client (react)
Meyer
MeyerOP•2y ago
thanks
ManuRodgers
ManuRodgers•2y ago
Hey mate, can you give me some code example in terms of how to use Pusher or Ably with trpc?
Neto
Neto•2y ago
const appRouter = router({
someMutation: publicProcedure
.mutation(async ({ ctx }) => {
ctx.pusher.trigger('some-channel', 'some-event', {
message: "hello world",
})
}),
});
const appRouter = router({
someMutation: publicProcedure
.mutation(async ({ ctx }) => {
ctx.pusher.trigger('some-channel', 'some-event', {
message: "hello world",
})
}),
});
pass the pusher instance in a higher middleware
Meyer
MeyerOP•2y ago
and in the client use pusher js to subscribe
Want results from more Discord servers?
Add your server