Skip to Content
Menu
This question has been flagged
2 Replies
2668 Views

I'm trying to send a SMS message via python in an automated action. I couldn't find any specific documentation regarding this but I did come across a couple of similar posts. 


I've tried this:
sms_pool = env['sms.template']
sms_template = sms_pool.search(['&', ('model_id', '=', 'sale.subscription'), ('id', '=', 9)])
sms_template.send_sms(subscription.id)


Which is similar to how I send email templates. But I receive "send_sms" is not a function. If this technique works, what function should I use (instead of 'send_sms') to send the message?


I've also tried:
#sms_obj = env['sms.composer'].create({
# 'numbers': sms_phone,
# 'body': sms_body
#})
#sms_obj.action_send_sms()

but I receive an invalid recipient message. I've tried to format the phone number in various ways without success. 


Can someone please point me in the right direction regarding what I'm missing to make this happen.


Avatar
Discard
Author Best Answer

Thank you for the response. Unfortunately, I'm still having trouble with this technique as well. I am trying to do this from within an Automated Action (not the back-end Python libraries, which is where it looks like your example is meant to be used).


From what I can tell, I have the SMS module installed and working properly. I have "sms.api" available in my "Models" list. I have sufficient credits purchased for sending a SMS message. I can successfully send a SMS message to a Contact when I do so manually or as part of SMS Marketing campaigns. 


Whenever I call sms_api.send_sms, I receive the following error:

ValueError: : "'sms.api' object has no attribute 'send_sms'" while evaluating


Avatar
Discard
Best Answer

Here's an example of how you can send an SMS message using this module:

from odoo import api, models

class YourModel(models.Model):
_name = 'your.model'

def send_sms_message(self):
# Get the SMS API object
sms_api = self.env['sms.api']

# Define the recipient phone number and message body
recipient_number = '123456789' # Replace with the actual recipient phone number
message_body = 'Hello, this is a test SMS message.'

# Send the SMS message
sms_api.send_sms(recipient_number, message_body)

In this example, you can create a method send_sms_message in your model and call it to send an SMS message. Replace '123456789' with the actual recipient's phone number, and 'Hello, this is a test SMS message.' with the desired message body.

Make sure you have the sms module installed and configured correctly in your Odoo instance. Also, ensure that you have configured the SMS gateway settings in Odoo, including the SMS API credentials.

If you're still facing issues with sending SMS messages, double-check the recipient's phone number format. It should follow the format expected by your SMS gateway provider (e.g., including the country code).

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 23
1436
2
Dec 23
4950
1
Nov 22
1968
1
Aug 22
2141
2
Jan 22
5055