Send us a text message to
Send us a text message to
timestamp | caller number | message |
---|
const { createHistoryModule, sipgateIO } = require("sipgateio");
const { HistoryEntryType } = require("sipgateio/dist/history");
const sipgateio = sipgateIO({
token_id: process.env.SIPGATE_TOKEN_ID,
token: process.env.SIPGATE_TOKEN
});
const historyModule = createHistoryModule(sipgateio);
console.log("Waiting for SMS...");
setInterval(() => {
historyModule
.fetchAll({
types: [HistoryEntryType.SMS],
directions: ["INCOMING"],
archived: false,
})
.then((messages) => {
messages.forEach((message) => {
console.log(`SMS received:\n${message.smsContent}`);
});
historyModule.batchUpdateEvents(messages, () => ({
archived: true,
}));
})
.catch(console.error);
}, 5000);