Casper has touted itself not simply as a retailer, but as a company based around the entire culture of sleep. The startup's main product is mattresses, but it also makes pillows and dog beds, publishes a sleep-centric blog, and hosts an annual sleep symposium.

Now the company is venturing into the world of artificial intelligence. On Wednesday, Casper is rolling out a chatbot targeted toward people who have trouble sleeping--just send it a text and it'll talk with you, (hopefully) much in the way a human would.

The chatbot, called Insomnobot3000 and accessible via text, is the result of months of secretive development by a 10-person team spanning Casper's tech, design, data, and creative departments.

The initiative was simple: "We wanted to make a bot that made 3 a.m. a little less lonely," says Lindsay Kaplan, Casper's head of communications. That entailed using test groups that started with Casper employees, then expanded into friends of friends.

To test the believability of Insomnobot3000, Casper had its earliest subjects hold conversations and give their feedback--without telling them until afterward they had been interacting with a bot. They also let users chat at various points throughout the day. What they found was those late-night topics were vastly different: Insomniacs kept circling back to topics that were keeping them up--work stress, coffee, or something they'd just watched on TV--or to welcome distractions, like weekend plans.

The team then built out a wide range of responses, honing in on the oft-repeated subjects, and used algorithms to create a bot personality the company describes as "universally friendly." It will understand common phrases and pop culture references--so if the finale of Stranger Things is what's preventing you from shutting your eyes, the Insomnobot is ready to talk about it.

There was much discussion about how the chatbot should talk, including a two-week debate about whether it should respond in lower case or with proper grammar. Eventually, the latter won, since most phones autocorrect to this format anyway.

For inspiration, the team hearkened back to Smarter Child, the fairly benign AOL Instant Messenger-based bot that used to provide bored tweens with entertainment back in the early 2000s--though some of Casper's younger employees had to read Wikipedia to become familiar with it.

The chatbot doesn't use machine learning, which is to say it won't grow smarter on its own. But Casper's team of engineers will be constantly updating the service as it collects more data on what people like to talk about and what kinds of responses are most desired.

Insomnobot3000 is free to use. The Casper team wouldn't talk monetization opportunities, but it's probably not unreasonable to assume that interacting with the bot via your phone offers the company a way to contact you about promotions. Casper pulled in $100 million in sales last year and is on pace for $200 million this year.

Time will tell what kind of usage this gets and how helpful a mass audience will actually find it. And as with Smarter Child and every other chatbot ever made, it's inevitable that people will use it for some pretty weird or lewd stuff. But the convos are private, so that's on them. And Casper stresses this isn't a gimmick but rather a way to give customers "great experiences."

Given its purpose, the bot has been designed to function best between 11 p.m. and 5 a.m. Text it outside of that window, and it'll politely brush you off and tell you to check back in later.

And to make the interactions feel less like a one-way street and more like you're talking to a person, the bot will also occasionally initiate late-night conversations--so if you're not looking to shoot the breeze with a robot before bed, make sure your phone's on silent.