SMS Reply Y (Yes)

Your software
My Mautic version is: 4.4
My PHP version is: 7.4.33
My Database type and version is: 5.7.39-42-log / pdo_mysql

Your problem
My problem is: So I wanted to know if there was an issue with the SMS ?
I know that I made the connection right but no error log is set and in the Plugins folder for mautic there no Folder for Twilio? Which seem strange. So does a folder need to be there ? Also doesn seem that Auth Token is capturing the details
which me back to the folder.

Thank you

Hi, can you plz rephrase your question? Im not sure what you are trying to ask.

Hi everyone

I have one question related with sending a webhook, where I need to send an info as ARRAY instead of STRING

I am trying to send a webhook, including one data field that should be considered as an ARRAY.

We are trying to send SMS as follows:

“to”: [“34666555444”],

But Mautic is sending this information as follows

“to”: “[34666555444]”

For this reason the API we are using is not able to understand the info, and is not sending the SMS properly

Does anyone can assist os to inform us how to send SMS as in BOLD letters above?

Thanks in advance for your support

Julio

The issue you’re experiencing is related to how the data is being formatted before it’s sent by the webhook. It seems that Mautic is treating the array as a string instead of an actual array. To address this, you need to ensure that the data is properly formatted as a JSON array in the payload.

Here are a few steps to help you achieve this:

  1. Check the Mautic webhook configuration: Ensure that the data field in the webhook configuration is set to handle JSON objects properly. Sometimes, webhooks have settings that determine how data is formatted.

  2. Modify the payload: If you have access to modify the payload before it’s sent, make sure the phone numbers are sent as a JSON array, not a string. Here’s an example in JSON format:

    {
        "to": ["34666555444"]
    }
    
  3. Use custom scripting: If Mautic doesn’t natively support this and you can’t modify the payload directly through the Mautic UI, you may need to use a script or middleware to reformat the data before sending it.

Example Using a Script

If you can add a script in between Mautic and your API to reformat the data, you could use something like this in a language of your choice (e.g., JavaScript with Node.js):

const axios = require('axios');

let payload = {
    "to": ["34666555444"] // Ensure this is formatted as an array
};

// Send the webhook
axios.post('https://your-api-endpoint.com/webhook', payload)
    .then(response => {
        console.log('Success:', response.data);
    })
    .catch(error => {
        console.error('Error:', error);
    });

Middleware Option

Another approach is to use middleware to intercept and reformat the webhook data. Tools like Zapier, Integromat (now Make), or a custom server can serve this purpose. Here’s a conceptual example:

  1. Receive the webhook from Mautic.
  2. Parse the received data.
  3. Reformat the to field to ensure it’s an array.
  4. Send the reformed data to your SMS API.
const express = require('express');
const axios = require('axios');
const app = express();

app.use(express.json());

app.post('/reformat-webhook', (req, res) => {
    let payload = req.body;

    // Ensure the 'to' field is an array
    if (typeof payload.to === 'string') {
        payload.to = JSON.parse(payload.to);
    }

    // Send the reformatted payload to the actual SMS API
    axios.post('https://your-sms-api.com/send', payload)
        .then(response => {
            res.status(200).send('SMS sent successfully');
        })
        .catch(error => {
            res.status(500).send('Failed to send SMS');
        });
});

app.listen(3000, () => {
    console.log('Middleware server running on port 3000');
});

In this setup, Mautic sends the webhook to your middleware server, which then reformats the data and forwards it to the SMS API.

Conclusion

Ensure that the data sent is properly formatted as a JSON array, either by configuring Mautic correctly if possible or by using a script/middleware to reformat the data before it reaches the SMS API. This should resolve the issue with the API not recognizing the to field as an array.