Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
3195 Vizualizări

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.


Imagine profil
Abandonează
Autor Cel mai bun răspuns

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


Imagine profil
Abandonează
Cel mai bun răspuns

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).

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
nov. 23
2259
2
dec. 23
5895
1
nov. 22
2738
1
aug. 22
2747
2
ian. 22
5965