简体   繁体   中英

Django-slack unable to send bot messages

I am trying to use django-slack api, I followed the path described here http://django-slack.readthedocs.io/ But I am not able to send sample bot message.

Here is my code snippet:

message.slack

{% extends django_slack %}
{% block text %}
Hello World!
{% endblock %}

in views.py

def index(request):
  slack_message('message.slack')
  return HttpResponse('Sent a message')

Can someone please help me on this?

As vadimchin already mentionded this django-slack doesn't work when DEBUG=True .

Check documentation about slack backend setting

So the slack backend is disabled when DEBUG=True . I prefer to also test the slack messages by sending them to a test channel, so I have added the following to my global settings.py :

SLACK_BACKEND='django_slack.backends.UrllibBackend'
SLACK_CHANNEL='#test'

This will overwrite the default backend (and channel).

You could try generating the API call on RapidAPI . I've linked you to Slack's postMessage endpoint on the platform. There you can generate an API call code snippet in python to put directly in your Django project.

You can also test out the API call within the dashboard :) The dashboard looks like this:

在此处输入图片说明

Just fill in your credentials and parameters, click code, and choose Python as your language.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM